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'); 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 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 }); Link to comment https://forums.phpfreaks.com/topic/287305-change-attr/#findComment-1476059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.