Reputation: 156
I need to get an element from its id, something along the lines of this:
$(this).parent().hasId('foo')
How can I accomplish this using jQuery?
Upvotes: 0
Views: 4781
Reputation: 752
JS
document.getElementById('ID').parentNode.id
JQuery
$('#ID').parent().attr('id');
See here : JSFiddle
EDIT:
Not sure that's you asking about..
Upvotes: 2
Reputation: 10246
You can get ID of parent Div in
Javascript as:
this.parentNode.id
and jQuery:
$(this).parent("#foo")
Upvotes: 0
Reputation: 176896
$("#idofelemnt")
- make sue of id selector that is will resolve issue...
if($("#idofelemnt").length == 0)
alert('element not exists');
else
alert('element exists');
or in your case
$(this).parent("#idofelemnt").length
Upvotes: 4
Reputation: 3436
something like this?
if($(this).parent().attr("id")=='foo'){
//do your stuff;
}
Upvotes: 0
Reputation: 23
I hope you want to get element object from his id. Simply use $('#elementId')
for getting that element object.
Upvotes: 0