jquery - Get contents of a clicked div -
i have string of divs same css class (.nav_div), different text in each, in navigation bar. they're set this:
<div class=nav_div>contact</div>...
i set divs enter function when clicked, this:
$('.nav_div').click(nav_is_clicked);
in function nav_is_clicked()
, want store contents of div clicked in variable called div_text
, i'm having trouble. did not work:
var div_text = $(this).contents().text();
how text div clicked?
thanks.
just use text()
. contents()
gives "the children of each element in set of matched elements, including text , comment nodes.", not want.
$('.nav_div').click(nav_is_clicked); function nav_is_clicked() { var div_text = $(this).text(); }
edit -
it looks original code work: http://jsfiddle.net/slves/
are binding click handler before element exists (like before page loaded)?
Comments
Post a Comment