/    Sign up×
Community /Pin to ProfileBookmark

recognise div (perhaps by identifying the content?)

In a previous message I sought a way to move a div while zooming the image within that div. I solved that problem and everything turned out very nicely. But…

Problem is now that I don’t know how to dynamically recognise the div I want to move.

Just imagine having 2 divs (div1 and div2), each containing an image. I want to allow the user to make these images larger just by moving the mouse over the image.

When I call the zoom function by onmouseover I need to recognise that the image is within div1 or div2. Else I may move the wrong image whiling zooming the other..

Any clues?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanMar 14.2004 — Just give the div an ID: example: <div ID="content1">Test</div>


then you can go this in a script:

<i>
</i>&lt;script language="javascript" type="text/javascript"&gt;
&lt;!--
var DIV1 = document.getElementById("content1");
//--&gt;
&lt;/script&gt;



When using that make shure you spell getElementById corretly. Exactly like that.
Copy linkTweet thisAlerts:
@v_ng0dl05authorMar 15.2004 — Thanks, but I knew using id's could make my life easier ;-)

I needed those already to move my divs in the first place.

What I was looking for was this.parentNode.id.

So when I browse over the image in the div, I can read the id of the div the image belongs to.
Copy linkTweet thisAlerts:
@sciguyryanMar 15.2004 — Hmm, I see

You could use a .innerHTML to find specific text inside a div...
Copy linkTweet thisAlerts:
@Mr_JMar 16.2004 — This may help


For IE

event.srcElement.parentNode.id


For Moz

e.target.parentNode.id


Using the following as an example

<script>

ns=document.getElementById&&!document.all

function hmm(){

if(!ns){

alert(event.srcElement.parentNode.id)

}

else{

alert(e.target.parentNode.id)

}

}

</script>


<div id="div1"><img id="pic1" width=200 onmouseover="hmm()"></div>
×

Success!

Help @v_ng0dl05 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...