/    Sign up×
Community /Pin to ProfileBookmark

document object model for p[]?

I have found some DOMs for objects like images, but is there a DOM for P’s?

I haven’t been able to find abything, but before I give up I thought I would ask here.

Basically what I’m trying to do I find the x,y coordinates for a specific P tag.

thanks in advance for any help.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJun 10.2005 — You can address any given P element with somethng like [font=monospace]document.getElementsByTagName ('P')[0][/font]. But getting the X,Y coordinates is something else.
Copy linkTweet thisAlerts:
@KorJun 10.2005 — give your <p> an id, let's say 'bla':
[code=php]
<script type="text/JavaScript">
function findPos(){
var obj = document.getElementById('bla');
var posX = obj.offsetLeft;
var posY = obj.offsetTop;
while(obj.parentNode){
posX=posX+obj.parentNode.offsetLeft;
posY=posY+obj.parentNode.offsetTop;
if(obj==document.getElementsByTagName('body')[0]){
break
}
else{obj=obj.parentNode;
}
}
alert(posX+'-'+posY)
}
onload=findPos;
</script>
[/code]


You may use the index of that specific <p> tag in the [b]document.getElementsByTagName('p')[/b] collection as well. It depends on what you want to do.
Copy linkTweet thisAlerts:
@CharlesJun 10.2005 — You may use the index of that specific <p> tag in the [b]document.getElementsByTagName('p')[/b] collection as well. It depends on what you want to do.[/QUOTE]Do note, however, that in HTML it is [b]document.getElementsByTagName('P')[/b] but in XHTML it is [b]document.getElementsByTagName('p')[/b].
Copy linkTweet thisAlerts:
@KorJun 10.2005 — document.getElementsByTagName('p') works perfectly in HTML as well (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">)
Copy linkTweet thisAlerts:
@super_code_monkauthorJun 10.2005 — thank you both for your help.

I really appreaciate it. I have finally got my rollover text dropdown menu working.
Copy linkTweet thisAlerts:
@CharlesJun 10.2005 — In HTML all element names are uppercase, it's just that HTML is case insensitive. JavaScript, however, is case sensitive. Just because a few browsers add a little normalizing to the method doesn't mean that all of them do. Besides, we might as well be syntactically correct.
×

Success!

Help @super_code_monk 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 5.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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