Brad Bansner
asked on
Use jQuery/Javascript to select parent DIV by class
I am trying to get the ID of the parent <div> when "return to top" is clicked, using the following code:
console.log($(this).parent ('p').prev All('.subp age').attr ('id'));
Here is my markup:
It just keeps returning "undefined", though. What am I doing wrong?
Thanks!
console.log($(this).parent
Here is my markup:
<div id="mvi2" class="subpage">
<p>Lots of content here.</p>
<p><a class="subpagetop" href="javascript:void(0)">RETURN TO TOP</a></p>
</div>
It just keeps returning "undefined", though. What am I doing wrong?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yep. Caught my mistake, but too late to correct it. I should have said...
console.log($(this).parent ('p').pare nt('div'). attr('id') );
console.log($(this).parent
ASKER
Thanks so much!
'welcome! have a nice week-end!
console.log($(this).parent
...should do it.