FAQ Database Discussion Community


Trouble with finding class element names in Javascript

javascript,html,class,getelementsbyclassname
I'm trying to grab the Names of some Class Elements in a document (there are several of them) and rotate through them. The HTML code of the site looks like this: <div class="parent"> <div class="item"> <a class="item-name" href="http://somerandomurl.com">Relevant Item</a> If I wanted to grab the URL I know the solution...

Class name to find nested tagname and assign value in Javascript

javascript,getelementsbytagname,getelementsbyclassname
I have the following markup which I can't modify: <li class="campID"> <label for="input_2_14">Name</label> <div> <input name="input_14" id="input_2_14" type="text" value="" class="medium" tabindex="11"> </div> </li> I want to select the input and change its value using vanilla JS (assume jQuery is not available). I can't use the input name or ID as...

Remove portion of text using GetElementsByClassName

javascript,replace,getelementsbyclassname
I'm trying to use the following script to remove ".00" from all prices on a page I'm working on. The ".00" is built in automatically by the WP theme I'm working with. Here's the script I'm using: <script> window.onload = function() { var str = document.getElementsByClassName("hungry-menu-item-price").innerHTML; var res = str.replace(".00",...

Changing class of elements

javascript,css,getelementbyid,getelementsbyclassname
I want to set up floating elements in a way it would depend of their amount. <div id="whatever"> <div class="iwantthischangedto3elements"> <a href="#">element 1</a> <a href="#">element 2</a> <a href="#">element 3</a> </div> <div class="iwantthischangedto2elements"> <a href="#">element 1</a> <a href="#">element 2</a> </div> </div> I can't really figure how to do this. I'm guessing...

jquery get elements by class name

html,arrays,parsing,getelementsbyclassname
I'm using Jquery to get a list of elements having a class "x". html: <p class="x">Some content</p> <p class="x">Some content#2</p> If we use Jquery to get both these html elements and do something with it- we use something like: $(".x").text("changed text"); This will change the text of both the paragraphs....

How can I determine the value of the selected dropdown option using getElementsByClassName?

javascript,select,html-select,getelementsbyclassname
How can I determine the value of the selected dropdown options using javascript. I can't use id selector so I was trying with document.getElementsByClassName. I understand that returns a set of values. Here is a simplified code I am trying to use: <div id="MDL" class="dates"> <p>Select Dates and Price</p> <select...

Get elements 'tag name' by searching Class name

javascript,html,getelementsbytagname,getelementsbyclassname
I'm trying to get element tag name which is associated with the element with a certain class name. I know I can do these two lines of code to get the class name and the tag name. document.getElementsByTagName("regeneratePostnatal"); document.getElementsByClassName(returnedPatientID); I'm just asking if there is a way of doing something...

javascript getelement where value contains specific string

javascript,html,getelementbyid,getelementsbytagname,getelementsbyclassname
I was wanting to count the occurrences of input fields that has a class name of text where that text input contains a specific value. document.getElementById('c_files').getElementsByClassName('text').length; So far this counts all textboxes with the class name of text but how can i make it value specific, say if i have...