• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

Get value of id using jQuery

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.
0
Tom
Asked:
Tom
1 Solution
 
Mukesh YadavFull Stack DeveloperCommented:
Try this ;)
<script>
$(function(){
  console.log($('div.foo div.bar').attr('id'));
});
</script>

Open in new window

0
 
TomAuthor Commented:
Excellent!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now