getelementbyid

document.getElementById('btnid').disabled is not working in firefox and chrome

帅比萌擦擦* 提交于 2019-11-27 05:43:43
问题 I'm using JavaScript for disabling a button. Works fine in IE but not in FireFox and chrome, here is the script what I'm working on: function disbtn(e) { if ( someCondition == true ) { document.getElementById('btn1').disabled = true; } else { document.getElementById('btn1').disabled = false; } And in my html I have: <input type="button" id="btn1" value="submit" /> 回答1: use setAttribute() and removeAttribute() function disbtn(e) { if ( someCondition == true ) { document.getElementById('btn1')

getElementById.contentDocument error in IE

≡放荡痞女 提交于 2019-11-27 05:00:47
<html> <script type="text/javascript"> function func() { alert(document.getElementById('iView').contentDocument); } </script> <body> <iframe id="iView" style="width:200px;height:200px;"></iframe> <a href="#" onclick="func();">click</a> </body> </html> After click, Firefox returns [object HTMLDocument]. Internet Explorer returns undefined. How can I select the iView element with Internet Explorer? Thanks. From this page : Mozilla supports the W3C standard of accessing iframe's document object through IFrameElm.contentDocument, while Internet Explorer requires you to access it through document

Get element inside element by class and ID - JavaScript

孤人 提交于 2019-11-27 03:05:24
Alright, I've dabbled in JavaScript before, but the most useful thing I've written is a CSS style-switcher. So I'm somewhat new to this. Let's say I have HTML code like this: <div id="foo"> <div class="bar"> Hello world! </div> </div> How would I change "Hello world!" to "Goodbye world!" ? I know how document.getElementByClass and document.getElementById work, but I would like to get more specific. Sorry if this has been asked before. Well, first you need to select the elements with a function like getElementById . var targetDiv = document.getElementById("foo").getElementsByClassName("bar")[0]

Selecting second children of first div children in javascript [duplicate]

故事扮演 提交于 2019-11-27 02:33:35
问题 This question already has answers here : querySelector with nested nth-child in Chrome doesn't appear to work (2 answers) Closed 8 months ago . I have an html that look something like this: <div id="mainDiv"> <-- I have this <div> <div></div> <div></div> <-- I need to get this </div> <span></span> <more stuff /> </div> i am using: var mainDiv = document.getElementById('mainDiv'); because I need that div in a var, but i also need to get that second div on the first div inside mainDiv into a

“getElementById not a function” when trying to parse an AJAX response?

笑着哭i 提交于 2019-11-27 02:13:15
I'm running GM_xmlhttpRequest (in a Greasemonkey script) and storing the responseText into a newly created HTML element: var responseHTML = document.createElement('HTML'); ... onload: function() { responseHTML.innerHTML = response.responseText; } And then I am trying to find an element in responseHTML : console.log(responseHTML.getElementsByTagName('div')); console.log(responseHTML.getElementById('result_0')); The first works fine, but not the second. Any ideas? getElementById is not a method of HTML elements. It is a method of the document node. As such you can't do: div.getElementById('foo')

Javascript getElementById lookups - hash map or recursive tree traversal?

帅比萌擦擦* 提交于 2019-11-27 00:52:58
问题 Does the DOM have a hash-table of elements whose keys are the elements' ids? I want to know if document.getElementById looks up a hash table or traverses the entire tree. Is this behavior different across browsers? 回答1: Implementations are free to do whatever they like, but since id is defined as a unique value, it would seem sensible to use a hash map or similiar lookup mechanism rather than traversal. What seems sensible from the outside, though, may not be when you get into the plumbing of

Cannot read property 'addEventListener' of null

守給你的承諾、 提交于 2019-11-26 23:55:41
I have to use vanilla JavaScript for a project. I have a few functions, one of which is a button that opens a menu. It works on pages where the target id exists, but causes an error on pages where the id doesn't exist. On those pages where the function cannot find the id, I receive a "Cannot read property 'addEventListener' of null " error and none of my other functions work. Below is the code for the button that opens the menu. function swapper() { toggleClass(document.getElementById('overlay'), 'open'); } var el = document.getElementById('overlayBtn'); el.addEventListener('click', swapper,

Powershell, ie9 and getElementById

Deadly 提交于 2019-11-26 23:30:59
问题 I use successfully a script for web automation from this site: heise web automation I know it is in german, but perhaps someone can help. The important part of the e-plus website: <tr> <td class="td1">Benutzername:</td> <td class="space"><img src="/img/c.gif" alt="" /></td> <td class="td2"><input type="text" id="IDToken1OL" name="IDToken1" onfocus="setToken(this)" onblur="getToken(this)" value="Benutzername" /></td> </tr> <tr> <td class="td1">Passwort:</td> <td class="space"><img src="/img/c

Set document.getElementById to variable

牧云@^-^@ 提交于 2019-11-26 21:53:06
问题 The following works: $ = document.form; x = $.name.value; This doesn't: $ = document.getElementById; x = $("id").value; Any ideas on why this doesn't work or how to make it so? 回答1: The value of this depends on how you call the function. When you call document.getElementById then getElementById gets this === document . When you copy getElementById to a different variable and then call it as $ then this === window (because window is the default variable). This then causes it to look for the id

Why is document.GetElementById returning null [duplicate]

假如想象 提交于 2019-11-26 19:01:11
This question already has an answer here: Why does jQuery or a DOM method such as getElementById not find the element? 8 answers I've been using document.GetElementById succesfully but from some time on I can't make it work again. Old pages in which I used it still work but things as simple as this: <html> <head> <title>no title</title> <script type="text/javascript"> document.getElementById("ThisWillBeNull").innerHTML = "Why is this null?"; </script> </head> <body> <div id="ThisWillBeNull"></div> </body> </html> Are giving me "document.getElementById("parsedOutput") is null" all the time now.