Reputation: 553
im searching for the Element whicht Provides the Name of a Parent. This:
$('.Item').click(function(){
var a = $(this).parent();
alert(a[0].tagName);
});
just says "DIV", but I need the real name of a Element. Thanks
Upvotes: 10
Views: 36296
Reputation: 11
var a = $(this).parent(); alert(a[0].nodeName.toLowerCase()); //Tag Name
alert($(a[0]).attr('name')); //Attribute (real) name
//OR
alert(a.attr('name')); //Attribute (real) name getting issue on this code
Upvotes: 1
Reputation: 955
You could just use plain Javascript for this - in this case it's even simpler (I think):
$('.Item').click(function() {
var parent = this.parentElement;
var tagName = parent.tagName; // tag name, like 'div', 'a', etc...
var name = parent.name // value of the 'name' attribute
});
My source: JavaScript DOM. Take a look at it, and help yourself.
Edit: wrapped code inside the click event handler.
Upvotes: 1
Reputation: 12541
Try the following (Alerts the tag name, and then the Real Name) :
I used $(a[0]).attr('name');
e.g.
$('.Item').click(function() {
var a = $(this).parent();
alert(a[0].nodeName.toLowerCase()); //Tag Name
alert($(a[0]).attr('name')); //Attribute (real) name
//OR
alert(a.attr('name')); //Attribute (real) name
});
Upvotes: 13
Reputation: 5912
look at this: http://jsfiddle.net/R833t/1/
$('.Item').click(function(){
var a = $(this).parent();
alert(a.attr('name'));
});
Upvotes: 1
Reputation: 121
if you want to get the attribute "name" you should use .attr()
$('.Item').click(function(){
var a = $(this).parent();
alert(a[0].attr("name"));
});
Upvotes: 0
Reputation: 5659
Use:
$('.Item').click(function(){
var a = $(this).parent();
alert(a.attr('name'));
});
Upvotes: 1