Reputation:
I think this should be a rather simple thing to do, but I'm completely hangin' here! I'm really not sure how much more descriptive I can be here, the title pretty much explains it all. It's a fairly odd situation because my google skills have completely failed me, and I know the solution is probably so simple to implement.
Would anyone care to explain this to me? Thanks.
EDIT:
Okay, never mind, apparently IE (which I'm testing in for compatibility reasons) doesn't do something correctly. I was using the correct method to do it, it just wasn't happening. But low-and-behold, as soon as I open it in Firefox it works.
Lesson I have learned today: Internet Explorer sucks!
Also, much kudos to those who helped... (I don't know if solve is the right word here) me diagnose this issue. Thanks!
Upvotes: 2
Views: 5546
Reputation: 8848
Step by step:
var $myElement = $('myElementSelector'); // get your element
var attrValue = $myElement.attr('someAttr'); // get the value of element's attribute
var $parent = $myElement.parent(); // get the element's parent element
$parent.attr('someAttr', attrValue); // set parent's attribute to child's value
The last three lines could be expressed more succinctly:
$myElement.parent().attr('someAttribute', $myElement.attr('someAttribute'););
Upvotes: 2
Reputation: 798
Not tested, but should roughly resemble this one:
var c = $('#child');
c.attr('title',c.parent().attr('title'));
Upvotes: 4