im looking for an element that provides the name of the parent. It:
$('.Item').click(function(){ var a = $(this).parent(); alert(a[0].tagName); });
just says "DIV", but I need the real name Element. Thanks
Try the following (Alerts the tag name and then the Real name):
I used $(a[0]).attr('name');
$(a[0]).attr('name');
eg.
$('.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 });
Try:
var a = $(this).parent().attr('name');
Using:
$('.Item').click(function(){ var a = $(this).parent(); alert(a.attr('name')); });
look at this: http://jsfiddle.net/R833t/1/
You can simply use simple Javascript for this - in this case it is 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 her and help yourself.
Edit: wrapped code inside click event handler.
var a = $ (this) .parent (); notification (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
if you want to get the name attribute, you should use .attr () $('.Item').click(function(){ var a = $(this).parent(); alert(a[0].attr("name")); });
$('.Item').click(function(){ var a = $(this).parent(); alert(a[0].attr("name")); });