Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving attributes of a paragraph tag 1

Status
Not open for further replies.

jamesp81

Programmer
Mar 3, 2006
19
US
I am currently passing the innerhtml of a paragraph tag to a function, which works well. What I also need to do is either pass the html of the paragraph tag itself, or at least programatically retrieve it's style attribute.

I did some google searching on this subject and found some code that looked like it should work, but it has done absolutely nothing but generate errors for me. Does anyone know what I need to do?
 
For IE only, you might try using "outerHTML" instead of "innerHTML" - but don't go that route if this needs to be cross-browser.

Failing that, you should be able to get the style attribute of the element no problem.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yeah, I'm trying to remain as compatible as possible.

It's not just getting the style attribute. I can do document.GetElementsByTagName('p').getAttribute('align') and it will tell me the alignment value of the paragraph, as text only. I guess what I'm wanting to do is capture the line of code that declares the paragraph itself. It would make feeding my function that works with the captured html a little simpler. It's not necessary, but it would make life a little easier, so I thought I'd check. But if outerhtml is an IE only thing, then I won't be going that route.

I know these are noob questions, but I am a Borland Delphi programmer by trade and I never really did pick up javascript.

Thanks for the help.
 
How about enclosing the paragraph in question within a <div> tag with the ID property set. Then you can use

document.getElementById("mydiv_name").innerHTML
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top