I want to select “#container” and “.active” and add “a” tags text “link here” to a variable and the log it.
<div id="container">
<div id="head"></div>
<div id="body"></div>
<ul>
<li class="item active">
<a class="link">link here</a>
</li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
</ul>
</div>
Here is my code so far… cant see the problem in it.. tried everything.
var tabid = $('#container.active a').text();
console.log(tabid);
Thanks for all help guys! peace out.
Your code is missing a space.
use:
or better, if your html structure stays the same:
also, you have to make sure your code is executed after the DOM is ready: