Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm new to jQuery. I assume this was asked hundred of times, but I couldn't find an answer.

I have a page in dotnetnuke in which I know the CSS Class but I need the element ID.
In this case I know that there will be only one element with the CSS Class.
How do I find it in jQuery?


Edit:

I want to move all children of the element with class FloatingFrameLightBlue1 to be children of PopupWrapper that i created a line before. But the append doesn't seems to work. what I'm doing wrong. the code I have:

.
.
jQuery("body").append("<div id='popupWrapper'></div>");

jQuery(".FloatingFrameLightBlue1").children().append("popupWrapper");
.
.
share|improve this question
Why do you need ID? – roasted 5 hours ago
1  
Shouldn't it be the other way around? You have an element with an ID, and there's only one element with that ID, and you'd like to know what class it has ? – adeneo 5 hours ago
@roasted I edited the question and added more details – Luis LL 5 hours ago

5 Answers

up vote 1 down vote accepted
var myID = $('.knownClass').attr('id');

This selects the element by the known class and results with the ID.

Check jQuery Selectors for more information!

share|improve this answer

Or use the DOM based solution (could be more efficient).

var id = $('.className').get(0).id;

share|improve this answer

You can parse the ID attribute by selecting the class:

$('.name_of_the_class').attr('id');
share|improve this answer

Try this code :

alert($('.myclass').attr('id'))
share|improve this answer

By using $('.name_of_class').doSomething(). If you want to select by ID, you can use ('#id').doSomething().

Any other attribute: $('div[attribute="value"]').doSomething().

To return the ID, replace .doSomething() by .attr('id').

share|improve this answer
so it seems that the problem is somewhere else. I edited and expanded my response, I would like to know what I'm doing wrong. – Luis LL 5 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.