Betty_S Posted March 18, 2007 Share Posted March 18, 2007 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 More sharing options...
PrateekSaxena Posted March 18, 2007 Share Posted March 18, 2007 var x = getElementsByTagName("div"); See this http://www.w3schools.com/htmldom/dom_nodes_access.asp Link to comment Share on other sites More sharing options...
jesh Posted March 19, 2007 Share Posted March 19, 2007 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 More sharing options...
PrateekSaxena Posted March 20, 2007 Share Posted March 20, 2007 The user hasnt read HTML DOM from the link above Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now