getelementbyid

Javascript getElementById base on partial string

ぃ、小莉子 提交于 2019-11-26 08:07:51
问题 I need to get the ID of an element but the value is dynamic with only the beginning of it is the same always. Heres a snippet of the code. <form class=\"form-poll\" id=\"poll-1225962377536\" action=\"/cs/Satellite\"> The ID always starts with \'poll-\' then the numbers are dynamic. How can I get the ID using just JavaScript and not jQuery? 回答1: You can use the querySelector for that: document.querySelector('[id^="poll-"]').id; The selector means: get an element where the attribute [id] begins

Why is document.GetElementById returning null [duplicate]

泪湿孤枕 提交于 2019-11-26 06:44:43
问题 This question already has answers here : Why does jQuery or a DOM method such as getElementById not find the element? (8 answers) Closed 4 years ago . 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>

How to pick element inside iframe using document.getElementById

你。 提交于 2019-11-26 04:24:47
I have a iframe like this <iframe name="myframe1" id="myframe1" width="100%" height="100%" src="a.html"> <html> <head></head> <frameset name="myframe2" cols="0%, 100%" border="0" frameBorder="0" frameSpacing="0"> <frame name="page1" src="c.html" scrolling="no"></frame> <frame name="page2" src="d.html" > <html> <head></head> <body id="top"> <div id="div1"> <div id="div2"> <div id="div3"> <ul id="x"> <li>a</li> <li>b</li> </ul> </div> </div> </div> </body> </html> </frame> </frameset> </html> </iframe> I want to refer to the element "x". I tried in several ways but I couldn't find a solution.

Selecting an element in iFrame jQuery

送分小仙女□ 提交于 2019-11-26 04:19:02
问题 In our application, we parse a web page and load it into another page in an iFrame. All the elements in that loaded page have their tokenid-s. I need to select the elements by those tokenid-s. Means - I click on an element on the main page and select corresponding element in the page in the iFrame. With the help of jQuery I\'m doing it in the following way: function selectElement(token) { $(\'[tokenid=\' + token + \']\').addClass(\'border\'); } However with this function I can select the

Getting the parent div of element

≡放荡痞女 提交于 2019-11-26 03:54:12
问题 This should be really simple but I\'m having trouble with it. How do I get a parent div of a child element? My HTML: <div id=\"test\"> <p id=\"myParagraph\">Testing</p> </div> My JavaScript: var pDoc = document.getElementById(\"myParagraph\"); var parentDiv = ?????????? I would have thought document.parent or parent.container would work but I keep getting not defined errors. Note that the pDoc is defined, just not certain variables of it. Any ideas? P.S. I would prefer to avoid jQuery if

JavaScript getElementByID() not working [duplicate]

本秂侑毒 提交于 2019-11-26 02:58:43
问题 This question already has an answer here: Why does jQuery or a DOM method such as getElementById not find the element? 8 answers Why does refButton get null in the following JavaScript code? <html> <head> <title></title> <script type=\"text/javascript\"> var refButton = document.getElementById(\"btnButton\"); refButton.onclick = function() { alert(\'I am clicked!\'); }; </script> </head> <body> <form id=\"form1\"> <div> <input id=\"btnButton\" type=\"button\" value=\"Click me\"/> </div> <

Javascript can&#39;t find element by id? [duplicate]

大憨熊 提交于 2019-11-26 02:38:52
问题 This question already has answers here : Why does jQuery or a DOM method such as getElementById not find the element? (8 answers) Closed 5 years ago . <html> <head> <title>Test javascript</title> <script type=\"text/javascript\"> var e = document.getElementById(\"db_info\"); e.innerHTML=\'Found you\'; </script> </head> <body> <div id=\"content\"> <div id=\"tables\"> </div> <div id=\"db_info\"> </div> </div> </body> </html> If I use alert(e); it turns up null .... and obviously I don\'t get

getElementById returns null? [closed]

假装没事ソ 提交于 2019-11-26 02:38:23
问题 document.getElementById(\'id of div that definately exists\') returns null. I originally loaded the javascript last in order to make sure I wouldn\'t need to worry about the onload event. I also tried using the onload event. It\'s very spooky. Any ideas or help would be greatly appreciated. 回答1: It can be caused by: Invalid HTML syntax (some tag is not closed or similar error) Duplicate IDs - there are two HTML DOM elements with the same ID Maybe element you are trying to get by ID is created

getElementById() returns null even though the element exists [duplicate]

删除回忆录丶 提交于 2019-11-26 02:11:28
问题 This question already has an answer here: Why does jQuery or a DOM method such as getElementById not find the element? 8 answers I\'m trying to get the element with getElementById(), but it returns null even though the element exists. What am I doing wrong? <html> <head> <title>blah</title> <script type=\"text/javascript\"> alert(document.getElementById(\"abc\")); </script> </head> <body> <div id=\"abc\"> </div> </body> 回答1: You have to put this in a document load event. The DOM hasn't gotten

How to pick element inside iframe using document.getElementById

谁都会走 提交于 2019-11-26 01:53:24
问题 I have a iframe like this <iframe name=\"myframe1\" id=\"myframe1\" width=\"100%\" height=\"100%\" src=\"a.html\"> <html> <head></head> <frameset name=\"myframe2\" cols=\"0%, 100%\" border=\"0\" frameBorder=\"0\" frameSpacing=\"0\"> <frame name=\"page1\" src=\"c.html\" scrolling=\"no\"></frame> <frame name=\"page2\" src=\"d.html\" > <html> <head></head> <body id=\"top\"> <div id=\"div1\"> <div id=\"div2\"> <div id=\"div3\"> <ul id=\"x\"> <li>a</li> <li>b</li> </ul> </div> </div> </div> </body