Ron Ron - 1 month ago 5
Javascript Question

Get class name from id in the last apperance of that div in jquery

<div class='user user1' id='newuser'></div>
<div class='user user2' id='newuser'></div>
<div class='user user3' id='newuser'></div>


For getting class name from id i can use
$('#newuser').attr('class');


Here how can i get the class name of the last div whose id is newuser ?

if id need to unique then how can i get the class name of last class named user ?

Answer
alert($("div[id='newuser']").last().attr('class'));

Or

alert($("[id='newuser']").last().attr('class'));

Above code will get the class name and alert it. Hope this will help you :)