Need to copy the text inside an <a> tag and move it inside a specific <div>
I have this piece of code:
<li class="selected"><a href="/AmIACandidate.html">Am I a Candidate?</a></li>
I need to grab the text "Am I a Candidate?"开发者_如何学Go from inside the tag and move it inside a specific div tag.
<div id="sideNavHeader"> --Copy needs to go here-- </div>
I can copy the whole
Thanks for any help
You probably want to use .text()
:
$('#sideNavHeader').text($('li.selected a').text());
Tobias Cohen's selector was much better than mine you should use:
$('#sideNavHeader').html($('li.selected a').html());
instead of my original code:
$('#sideNavHeader').html($('li.selected').children('a').html());
精彩评论