Jump to content

How to get div's elements?


Betty_S

Recommended Posts

Hi,How can retrive all of the tags or elemnts within a divI have this:

<div name="myDiv"><input type="text" value="txt1" name="txt1" /><input type="text" value="txt2" name="txt2" /><input type="text" value="txt3" name="txt3" /></div>

And that’s the script that didn't work:

var e=document.myDiv.elements; for (var i=0;i<e.length;i++)	{alert(e[i].name);}

What am I doing worng?

Link to comment
Share on other sites

var x = getElementsByTagName("div"); See this http://www.w3schools.com/htmldom/dom_nodes_access.asp

Link to comment
Share on other sites

You can get all of the inputs that are within a div by using this:

var div = document.getElementById("myDiv");var inputs = div.getElementsByTagName("input");

But, for the above to work, you'd have to have your div declared like this (with an ID attribute rather than a NAME):

<div id="myDiv">

Link to comment
Share on other sites

The user hasnt read HTML DOM from the link above :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...