getelementsbytagname

How to run getElementsByTagName on children of an element only?

陌路散爱 提交于 2019-12-10 14:49:36
问题 I'm having trouble getting a selector to work properly. I have this HTML: <div.wrapper> <div.ui-controlgroup-controls> <form> <div.ui-btn></div> </form> <div.ui-btn></div> <div.ui-btn></div> <div.ui-btn></div> <div.ui-btn></div> </div> </div> and I'm trying to select the div tags, which are children of ui-controlgroup-controls - which means excluding whats inside the form. This is what I'm trying: // el is my div.wrapper element el.children[0].getElementsByTagName("div"); However this does

getElementsByTagName(“*”) always updated?

时光毁灭记忆、已成空白 提交于 2019-12-10 04:57:45
问题 I have made this code: var foo=document.createElement("div"); var childs=foo.getElementsByTagName("*"); console.log(childs.length);//0 OK var a=document.createElement("a"); foo.appendChild(a); console.log(childs.length);//1 WTF? A fiddle: http://jsfiddle.net/RL54Z/3/ I don't have to write childs=foo.getElementsByTagName("*"); between the fifth and the sixth line so that childs.length is updated. How can it be? 回答1: Most lists of nodes in the DOM (e.g. returned from getElementsBy* ,

How do I get all h1,h2,h3 etc elements in javascript?

淺唱寂寞╮ 提交于 2019-12-10 01:06:28
问题 I want to write something like this in javascript: var all_headings = document.getElementsByTagName("h1,h2,h3,h4,h5,h6"); all_headings would then be a list of all elements that are h1 or h2 or h3 ... And in the order that they appear in the document, of course. How do I do it? 回答1: With modern browsers you can do document.querySelectorAll("h1, h2, h3, h4, h5, h6") Or you could get cross-browser compatibility by using jQuery: $("h1, h2, h3, h4, h5, h6") 回答2: If you are using jQuery you can use

change value of text using getElementsByName

核能气质少年 提交于 2019-12-08 17:45:17
问题 I have firstName text that I want to change his value but it not work - <input type="text" name="firstName" /> <script LANGUAGE="JavaScript" TYPE="text/javascript"> document.getElementsByName("firstName").[0].value = "New Value " ; </script> How can I change this value ? 回答1: That's not syntactically valid JS. Remove the extra . : // ↓↓ document.getElementsByName("firstName")[0].value = "New Value " ; // ↑↑ and the rest will work. 来源: https://stackoverflow.com/questions/11851682/change-value

cross-browser 'getElementsByTagName' with namespace from responseXML

陌路散爱 提交于 2019-12-07 03:38:50
问题 Am trying to read an XML response using getElementsByTagName : var rows = items.responseXML.getElementsByTagName("z:row"); for (var i=0; i<rows.length; i++) { //do something } Above code works fine in Firefox and IE but in chrome it throws null.. i mean it does not get any data.. when i alert the rows.length it gives me 0 always in chrome. Then i searched in google and understood the issue is with xsd:element , then i changed "z:row" to only "row" . Then it worked in Chrome but Firefox and IE

Recommended method to locate the current script?

荒凉一梦 提交于 2019-12-06 21:22:19
问题 I am writing a script that needs to add DOM elements to the page, at the place where the script is located (widget-like approach). What is the best way to do this? Here are the techniques I am considering: Include an element with an id="Locator" right above the script. Issues: I don't like the extra markup If I reuse the widget in the page, several elements will have the same "Locator" id. I was thinking about adding a line in the script to remove the id once used, but still... Add an id to

Getting attribute values in VBA

妖精的绣舞 提交于 2019-12-06 03:39:31
I need to make a VBA file that will read a webpage and return the value of the SRC attribute of the IMG tag. I wasn't able to make the last step work. Can you guys help me? <html> <body> <img src="image.jpg"> </body> </html> ===Edit=== I managed to return the attribute object. Now I need to return its value Option Compare Database Sub AcessaPagina() Dim ie As InternetExplorer Dim test As String Dim obj As Object Set ie = New InternetExplorer ie.Navigate "http://www.google.com.br" MsgBox ie.Document.getElementsByTagName("img").Item(0).Attributes("src") ie.Visible = True End Sub That's what I

cross-browser 'getElementsByTagName' with namespace from responseXML

独自空忆成欢 提交于 2019-12-05 07:00:46
Am trying to read an XML response using getElementsByTagName : var rows = items.responseXML.getElementsByTagName("z:row"); for (var i=0; i<rows.length; i++) { //do something } Above code works fine in Firefox and IE but in chrome it throws null.. i mean it does not get any data.. when i alert the rows.length it gives me 0 always in chrome. Then i searched in google and understood the issue is with xsd:element , then i changed "z:row" to only "row" . Then it worked in Chrome but Firefox and IE returned 0 for rows.length . Is there any method which across all browsers? This is what I use:

Recommended method to locate the current script?

筅森魡賤 提交于 2019-12-05 02:12:35
I am writing a script that needs to add DOM elements to the page, at the place where the script is located (widget-like approach). What is the best way to do this? Here are the techniques I am considering: Include an element with an id="Locator" right above the script. Issues: I don't like the extra markup If I reuse the widget in the page, several elements will have the same "Locator" id. I was thinking about adding a line in the script to remove the id once used, but still... Add an id to the script. Issues: even though it seems to work, the id attribute is not valid for the script element

How do I get all h1,h2,h3 etc elements in javascript?

混江龙づ霸主 提交于 2019-12-04 23:51:17
I want to write something like this in javascript: var all_headings = document.getElementsByTagName("h1,h2,h3,h4,h5,h6"); all_headings would then be a list of all elements that are h1 or h2 or h3 ... And in the order that they appear in the document, of course. How do I do it? With modern browsers you can do document.querySelectorAll("h1, h2, h3, h4, h5, h6") Or you could get cross-browser compatibility by using jQuery: $("h1, h2, h3, h4, h5, h6") If you are using jQuery you can use $(":header") example from jQuery documentation <script>$(":header").css({ background:'#CCC', color:'blue' });<