Get value of id using jQuery

Tom
Tom used Ask the Experts™
on
I'm attempting to create a GreaseMonkey script that will return the value of id in the following html:
<div class="foo">
                <div class="bar" id="random1234"></div>
</div>

Open in new window

In the above example random1234 would be returned.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Full Stack Developer
Commented:
Try this ;)
<script>
$(function(){
  console.log($('div.foo div.bar').attr('id'));
});
</script>

Open in new window

Tom

Author

Commented:
Excellent!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial