getelementsbyclassname

getelementbyclassname instead of getelementbyid is not working

无人久伴 提交于 2019-12-04 06:39:36
问题 I have read many times that you can NOW get getElementsByClassName. This below works fine IF I replace ClassName by Id, but using the word ClassName does not work. Anyone know why? (I tried on Chrome and Firefox) <script type="text/javascript"> function makeDisable(){ var x=document.getElementsByClassName("mySelect"); x.disabled=true } function makeEnable(){ var x=document.getElementsByClassName("mySelect"); x.disabled=false } </script> <form> <select class="mySelect" id="mySelect"> <option

Get all items that start with class name

安稳与你 提交于 2019-12-03 21:47:13
问题 I'm trying to only show certain div s. The way I have decided to do this is to first hide all elements that start with "page" and then only show the correct div s. Here's my (simplified) code: <form> <input type="text" onfocus="showfields(1);"> <input type="text" onfocus="showfields(2);"> </form> <div class="page1 row">Some content</div> <div class="page1 row">Some content</div> <div class="page2 row">Some content</div> <div class="page2 row">Some content</div> <script> function showfields

document.getElementByClassName - Cross Browser Fix

我与影子孤独终老i 提交于 2019-12-03 18:08:07
问题 I have looked at previous asks for help in a cross browser fix for document.getElementByClassName and found this link which provided a seemingly perfect fix. However I have tried implementing it on a site that I have built but can not get the fix to work (or any others) on IE8 (the browser which I am working to get compatability with). I am still getting the "Object or Property is not supported" error meaning that the fix is obviously not working. Coming up short for any reasons why this may

How do I append a child to all the nodes with the specified classname using pure javascript

不羁的心 提交于 2019-12-02 19:13:10
问题 var menuheader = document.createElement("li"); document.getElementsByClassName("subMenu").appendChild(menuheader); Above is the code snippet. I get this error: firebug: TypeError: document.getElementsByClassName(...).appendChild is not a function 回答1: It should be var menuheader = document.createElement("li");// creates main menu to which below submenu should be added. var submenus=document.getElementsByClassName("subMenu"); //gives an array so you cannot append child to that. for(int i=0;i

How do I append a child to all the nodes with the specified classname using pure javascript

限于喜欢 提交于 2019-12-02 09:11:14
var menuheader = document.createElement("li"); document.getElementsByClassName("subMenu").appendChild(menuheader); Above is the code snippet. I get this error: firebug: TypeError: document.getElementsByClassName(...).appendChild is not a function It should be var menuheader = document.createElement("li");// creates main menu to which below submenu should be added. var submenus=document.getElementsByClassName("subMenu"); //gives an array so you cannot append child to that. for(int i=0;i<submenus.length;i++){ menuheader.appendChild(submenus[i]); } From your code it seems that you are doing

getElementByID works, getElementsByClassName does not [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-02 08:59:37
问题 This question already has answers here : What do querySelectorAll and getElementsBy* methods return? (9 answers) Closed 4 years ago . I'm working on a solution that dynamically adds select input / dropdown boxes to a page. The example code below works if I give each select input a unique id and include a line of cod4e to the script using getElementById() but does not work if I use GetElementsByClassName(). My objective is to use one script to populate select input box without the need to

Struggling with classList.add and getElementsByClassName [duplicate]

和自甴很熟 提交于 2019-12-01 10:35:39
This question already has an answer here: What do querySelectorAll and getElementsBy* methods return? 9 answers I'm trying to add a extra class to some elements with a specific class(input-fieldset). <fieldset id="pay" class="input-fieldset"></fieldset> <fieldset id="address" class="input-fieldset"></fieldset> So I did some searches and found this: var element = document.getElementsByClassName('input-fieldset'); element.classList.add(' input-fieldset-awesome'); I'm trying to add the class input-fieldset-awesome. But it doesn't work, I get the error: Uncaught TypeError: Cannot read property

Struggling with classList.add and getElementsByClassName [duplicate]

一世执手 提交于 2019-12-01 08:37:40
问题 This question already has answers here : What do querySelectorAll and getElementsBy* methods return? (9 answers) Closed 5 years ago . I'm trying to add a extra class to some elements with a specific class(input-fieldset). <fieldset id="pay" class="input-fieldset"></fieldset> <fieldset id="address" class="input-fieldset"></fieldset> So I did some searches and found this: var element = document.getElementsByClassName('input-fieldset'); element.classList.add(' input-fieldset-awesome'); I'm

Get all items that start with class name

余生颓废 提交于 2019-12-01 00:04:43
I'm trying to only show certain div s. The way I have decided to do this is to first hide all elements that start with "page" and then only show the correct div s. Here's my (simplified) code: <form> <input type="text" onfocus="showfields(1);"> <input type="text" onfocus="showfields(2);"> </form> <div class="page1 row">Some content</div> <div class="page1 row">Some content</div> <div class="page2 row">Some content</div> <div class="page2 row">Some content</div> <script> function showfields(page){ //hide all items that have a class starting with page* var patt1 = /^page/; var items = document

How to get current element in getElementsByClassName

Deadly 提交于 2019-11-30 05:06:01
Consider a simple JS event of document.getElementsByClassName('test')[0].onclick=function(){ document.getElementsByClassName('test')[0].innerHTML = 'New Text'; } How can I extend this code to generally work for all elements with class="test" . I mean getting the element clicked and replace its content. In fact, we need to get the node number (provided inside the bracket) from the click event. I am trying to better understand javascript in unobtrusive codes, not a practical method like jQuery. Just iterate over them: var elements = document.getElementsByClassName('test'); for (var i = 0; i <