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!

Getting a handle of the containing div 1

Status
Not open for further replies.

flawless83

Programmer
Jun 10, 2011
2
Is it possible to find out the ID of an element or to get a handle of an element in which JS is located. For example if we have

<div id="unknown">
<script type="text/javascript>

get a handle of the containing div(in this case the div with an id "unknown")...for example to change it's innerHTML. If we don't know the id of the div.

</script>
</div>


Thanks in advance!
 
Nope, And I'm not sure how that could be possible. If you are building this you have to know the ID. also if you do manage to change the innerHTML of the div, you wipe out your javascript, and and it won't run again until you reload the page.

I think you need to re-think the logic that compels you to place a piece of script inside a div whose contents you want to modify.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thank you for your quick reply. I appreciate your help.
Let me just comment on the logic that got me thinking of that implementation.

I need to create a JS to parse the portion of HTML pages,for now i've made a script that parses the html contained between the body tags. basically all html. I would like to constrain the parsing for just one child element(preferably div) of a body html. Since all of the pages have different structure its impossible to get a handle by id because there's no uniformity between them.


Any advice on that?
 
If you want to get the content of a single element there needs to be a way for you to identify that element. In other words how do you select what element you want to parse.

Based on that piece of data, we can come up with the logic to get it done.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
you could use jquery has function to get all divs of body, or the first div,....


/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top