JavaScript and client side scripting.
Moderator: General Moderators
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Nov 30, 2006 6:13 pm
I have an image wrapped in an anchor tag...
Code: Select all
<a href="#url"><img src="#href" alt="Image" id="i_am_an_image"></a>
I have a reference to the image tag... how would I use that to grab the <a> tag that is it's parent?
Code: Select all
var img1 = document.getElementById('i_am_an_image');
//img1.parentNode ??
I want to disable the <a> tag's href but the only thing I have access to is the image
nickvd
DevNet Resident
Posts: 1027 Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:
Post
by nickvd » Thu Nov 30, 2006 6:33 pm
You answered your own question, next time try it first!
Code: Select all
document.getElementById('picture').parentNode.href = null
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Nov 30, 2006 6:46 pm
well I tried alert(img1.parentNode) and got "undefined" so I figured that wasn't it... but shortly after I posted here, I tried alert(img1.parentNode.href); and I got a url... sorry
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Mon Dec 11, 2006 11:55 am
It Would Be
===============
Code: Select all
document.getElementById('i_am_an_image').parentElement.href;
NOT parentNode
ITS parentElement