getelementsbyclassname

How to read the contents of a href with javascript?

旧巷老猫 提交于 2021-01-24 18:59:26
问题 I have the following html and am stumped as to how to read the contents of the href tag? <p class="xyz-title"> <a href="http://www.youtube.com/embed/xyz"> <span class="field-content">Title here</span> </a> </p> I tried document.getElementByClass('xyz-title')[0].innerHTML but that didn't work obviously. Thanks very much for pointing me in the right direction. 回答1: It is a syntax error. It is supposed to be getElementsByClassName. Use this instead: document.getElementsByClassName('xyz-title')[0

What do querySelectorAll and getElementsBy* methods return?

你离开我真会死。 提交于 2020-06-29 08:41:41
问题 Do getElementsByClassName (and similar functions like getElementsByTagName and querySelectorAll ) work the same as getElementById or do they return an array of elements? The reason I ask is because I am trying to change the style of all elements using getElementsByClassName . See below. //doesn't work document.getElementsByClassName('myElement').style.size = '100px'; //works document.getElementById('myIdElement').style.size = '100px'; 回答1: Your getElementById() code works since IDs have to be

Change value attribute by class via JavaScript

女生的网名这么多〃 提交于 2020-05-10 09:28:47
问题 I have the following HTML: <input class="vertical-tabs-active-tab" type="hidden" value="account" name="tabs__active_tab"> I need JavaScript that will change the value of "account" to "yolo". I thought I could do this: document.getElementsByClassName('vertical-tabs-active-tab').setAttribute("value", "yolo"); But that produces an error of: document.getElementsByClassName(...).setAttribute is not a function I'm not able to add an "id" to input, I have to change the value based on class. 回答1:

How do I select multiple elements of same tag but different classes? Using vanilla JS

大城市里の小女人 提交于 2020-05-09 16:24:05
问题 I have 6 inputs in a form, each with a class of .first .second .third .fourth .fifth .sixth respectively and I'd like to select them with vanilla JS but after trying with getElementsByClassName and querySelectorAll, it still didn't work out. here is my line of code: document.querySelectorAll("form input")[0].value=="" How do I select all the elements with those classes? Thanks in advance for any help rendered! 回答1: Your current code document.querySelectorAll("form input") is basically getting

How do I select multiple elements of same tag but different classes? Using vanilla JS

萝らか妹 提交于 2020-05-09 16:23:05
问题 I have 6 inputs in a form, each with a class of .first .second .third .fourth .fifth .sixth respectively and I'd like to select them with vanilla JS but after trying with getElementsByClassName and querySelectorAll, it still didn't work out. here is my line of code: document.querySelectorAll("form input")[0].value=="" How do I select all the elements with those classes? Thanks in advance for any help rendered! 回答1: Your current code document.querySelectorAll("form input") is basically getting

How to change button color onclick using javascript only?

拜拜、爱过 提交于 2020-03-20 06:17:31
问题 I was trying to make the color of the buttons change using onclick and getElementsByClassName and came up with something like this: HTML: <button onclick="submitButtonStyle()" type="submit" class="stylebutton"> Submit </button> JS: function submitButtonStyle() { document.getElementsByClassName("stylebutton").style.backgroundColor = "red"; } I would be really grateful if you guys gave me a hint about what is lacking in my code/what I should add etc. 回答1: getElementsByClassName returns an

How to change button color onclick using javascript only?

青春壹個敷衍的年華 提交于 2020-03-20 06:15:55
问题 I was trying to make the color of the buttons change using onclick and getElementsByClassName and came up with something like this: HTML: <button onclick="submitButtonStyle()" type="submit" class="stylebutton"> Submit </button> JS: function submitButtonStyle() { document.getElementsByClassName("stylebutton").style.backgroundColor = "red"; } I would be really grateful if you guys gave me a hint about what is lacking in my code/what I should add etc. 回答1: getElementsByClassName returns an

How to change button color onclick using javascript only?

人走茶凉 提交于 2020-03-20 06:13:56
问题 I was trying to make the color of the buttons change using onclick and getElementsByClassName and came up with something like this: HTML: <button onclick="submitButtonStyle()" type="submit" class="stylebutton"> Submit </button> JS: function submitButtonStyle() { document.getElementsByClassName("stylebutton").style.backgroundColor = "red"; } I would be really grateful if you guys gave me a hint about what is lacking in my code/what I should add etc. 回答1: getElementsByClassName returns an

DOM class name is not working for buttons

十年热恋 提交于 2020-01-24 23:08:10
问题 I have created a button and added tick glyphicon . so that when i clicked on the button the tick mark should be visible. I tried to apply to the buttons in my table using DOM element of Class Name using JavaScript. but it is not working if i click button the tick mark is appearing on all buttons but i want it when the specific button is clicked just like radio button can Anyone Help me function show(target) { // document.getElementById(target).style.visibility = 'visible'; var x = document

DOM class name is not working for buttons

南笙酒味 提交于 2020-01-24 23:07:02
问题 I have created a button and added tick glyphicon . so that when i clicked on the button the tick mark should be visible. I tried to apply to the buttons in my table using DOM element of Class Name using JavaScript. but it is not working if i click button the tick mark is appearing on all buttons but i want it when the specific button is clicked just like radio button can Anyone Help me function show(target) { // document.getElementById(target).style.visibility = 'visible'; var x = document