Glenskie Posted March 26, 2014 Share Posted March 26, 2014 Hi i want to change the attribute of a div id when the div is clicked.. but its not working for some reason ? $('#prev').attr('id',''); $('#next').attr('id','2'); //Pagination Click $(".controls").click(function(){ $("html, body").animate({ scrollTop: 0 }, 700); $('#next').removeattr('id',''); $('#prev').attr('id',''); $('#next').attr('id','7'); Quote Link to comment https://forums.phpfreaks.com/topic/287305-change-attr/ Share on other sites More sharing options...
mhmazrooei Posted April 14, 2014 Share Posted April 14, 2014 (edited) hi Glenskie. this is wrong. lets assume that you have two divs with same class name (controls) and two ids (prev, next) you should write your code like this: $('.controls').click(function() { $(this).attr('id', 'your desired id'); // rest of your code }); Edited April 14, 2014 by mhmazrooei Quote Link to comment https://forums.phpfreaks.com/topic/287305-change-attr/#findComment-1476059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.