getelementbyid

getElementById in React

天大地大妈咪最大 提交于 2020-08-21 04:26:28
问题 Getting this error at the moment: Uncaught TypeError: Cannot read property 'value' of null I call this in my render function below: <input type="submit" className="nameInput" id="name" value="cp-dev1" onClick={this.writeData}/> I also have tried calling it in here componentWillMount: function(){ var name = document.getElementById('name').value; }, How can I get the id of an input text field and read that value and ensure it is not null? I think the DOM is loading after I try to read the

How to grab the x, y position of html elements with javascript

假装没事ソ 提交于 2020-07-17 10:47:27
问题 I have in my html document several div elements with certain css class and want to get x, y position of those elements, thanks in advance. 回答1: Use getBoundingClientRect : http://ejohn.org/blog/getboundingclientrect-is-awesome/ For example: var div = document.getElementById("yourDiv"); var rect = div.getBoundingClientRect(); alert("Coordinates: " + rect.left + "px, " + rect.top + "px"); Remember that getBoundingClientRect gives the coordinates relative to the current viewport , which means

When to use the `#` symbol to get a DOM element?

天涯浪子 提交于 2020-07-13 00:25:47
问题 Sometimes I need to get elements like this: var object = document.getElementById('ObjectName'); And sometimes like this: var object = document.getElementById('#ObjectName'); What’s the difference between them? 回答1: No, you don't see var object = document.getElementById('#ObjectName'); You don't see that because that would mean the id of the element starts with # and HTML4 id could only start "with a letter ([A-Za-z])". What you see is sometimes people using the jQuery library in which the

Why does `document.getElementById(“#datepicker1”)` not find my element? [closed]

二次信任 提交于 2020-07-08 00:49:09
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question I am trying to show / hide a text input based on the selection of a drop down list. Here’s a JSFiddle to what I am trying to do. When I get into the function, I get a “ TypeError : Cannot set property ' type ' of null ” . This is the code: function

javascript: get contents of textarea, textContent vs. innerHTML vs. innerText

瘦欲@ 提交于 2020-04-05 17:40:49
问题 I am having trouble getting the contents of a textarea with js. I feel like I've done this many times before without problems but something is throwing it off or I have a mental block. html <textarea id="productdescript">test copy..asdfd</textarea><button value="Enter" onclick="addProduct()"> js function addProduct() { var descript = document.getElementById('productdescript').textContent; alert(descript); } Firefox is the only browser I have currently. When I use textContent, the alert box

How to use .contentDocument in a .hover variable path?

北战南征 提交于 2020-02-06 07:55:28
问题 I have an SVG loading like this: <object id="svg-object" type="image/svg+xml" width="1400px" height="900px" data="media/1.svg?"></object> I then have a function that works calling out one element in this svg and apply a style to it just fine. Here is the onload event that is working for getting me the element properly: window.onload=function() { var svgObject = document.getElementById('svg-object').contentDocument; var element = svgObject.getElementById('sprite1'); }; But how do I set a

How to use .contentDocument in a .hover variable path?

╄→尐↘猪︶ㄣ 提交于 2020-02-06 07:55:07
问题 I have an SVG loading like this: <object id="svg-object" type="image/svg+xml" width="1400px" height="900px" data="media/1.svg?"></object> I then have a function that works calling out one element in this svg and apply a style to it just fine. Here is the onload event that is working for getting me the element properly: window.onload=function() { var svgObject = document.getElementById('svg-object').contentDocument; var element = svgObject.getElementById('sprite1'); }; But how do I set a

Update anchor tag as you scroll past an element in a div

天涯浪子 提交于 2020-02-06 06:32:48
问题 I am not sure if this is possible that is why I am on here asking so if you have any ideas on how this would be possible then I would greatly appreciate it! Ok say that I have a div that scrolls with overflow-y feature. And say that inside of this div there is a story or large amount of text. Is there anyway to have Javascript memorize or save where you are at in this div maybe through a line number or anchor tag possibly? That way whenever the div is gone, such as if I had javascript change

Check with VBA if an element exists on the page

会有一股神秘感。 提交于 2020-02-02 15:15:05
问题 I have 15,000 products and I need to know if they're X, Y or Z. The code below checks on amazon to see if a product is a type of XYZ. God help me, it actually works. The only exception is when it searches a product no longer sold by Amazon. Then the element ID that I'm looking for which contains the product description that I'm searching doesn't exist on the page, and the code breaks on line text = document.getelementbyID("result_0").innertext with the error "Object variable or With block