Jump to content

[SOLVED] Searching through html/css with javascript


therealwesfoster

Recommended Posts

Here's my question..

 

I have some text in a webpage in between < b > tags, inside of a < div >. now, the div has an ID of "div"..

<div id="div"><p>bla bla bla</b><br><b>hey there</b></div>

 

can I acces the <B> tag like this?

 

var it = document.getElementById("div").b

 

if not, how would I access something like that with CSS inheritance? (example, html.body.div.b)

 

-------

 

Ok, that was Q number 1. Here's #2.

 

How can I search within a HTML file? for example, if I wanted to get a certain URL location, i would search for < a href ="HERE.html">fff and would be able to store HERE in a JS variable..

 

I hope that makes sense..

 

thanks!

Alright ive been reading up on that..

 

here's what i have.. i want to get the text of the 11th occurance of the < font > tag

 

html:

<font class="green">TEST TEXT</font>

 

javascript:

alert(document.getElementsByTagName('font')[10].firstChild);

 

but it returns (in an alert window)

 

[object Text]

 

but it should say TEST TEXT

 

???

<script language="javascript">
function getText()
{
alert(document.getElementsByTagName('font')[0].innerHTML);
}
</script>

</head><body onload="getText()">

<font class="green">TEST TEXT</font>

 

document.getElementsByTagName('font')[10].firstChild = will give you the 10th instance of the font tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.