Friday, 15 April 2011

how to get the id of a div when using jquery hasClass method? -



how to get the id of a div when using jquery hasClass method? -

this code not working:

$("div").hasclass("testsection").attr("id");

i next error message:

typeerror: $(...).hasclass(...).attr not function

any thought problem

assuming there 1 div specified class can utilize class in selector:

var id = $("div.testsection").prop("id");

if there multiple divs class, you'd need loop:

$("div.testsection").each(function() { var id = this.id; // id... });

jquery

No comments:

Post a Comment