Questions tagged [getelementsbyclassname]

getElementsByClassName is a Javascript function which takes a string argument and returns elements from the current page with a class name matching the string. It is generally used to gather DOM elements for further manipulation.

getElementsByClassName() is a function which

[r]eturns a set of elements which have all the given class names. When called on the document object, the complete document is searched, including the root node. You may also call getElementsByClassName on any element; it will return only elements which are descendants of the specified root element with the given class names. – (Mozilla Developer Network documentation)

664 questions
4
votes
1 answer

Surprisingly slow class selector in jQuery compared to 'getElementsByClassName' + Benchmarks

I'm writing some tests for a CMS, and I need to know if a certain classname is in the document. So I went to investigate what is the fastest way to check if a classname exists in the document. You can see my benchmarks here:…
jeroen
  • 502
  • 8
  • 17
4
votes
4 answers

Make getElementsByClassName to target every element

I am trying to make this script to target both of my class element with the same class name, but it is only targeting the first one. How can i make it to target both or all classes with same class name? https://jsfiddle.net/cprtkhmd/2/` var d =…
jan
  • 235
  • 1
  • 2
  • 12
4
votes
1 answer

Get one class in a function with index for a menu with underline hover

I'm working on an hover effect for a menu which worked well while using ID's but I can't figure how to do the same with multiples classes. The function is to get the width of the text and apply an underline on hover with the same length. It would be…
Léo Durand
  • 215
  • 1
  • 4
  • 13
4
votes
2 answers

Modify prototypes of every possible DOM element

Updated title to better reflect what I'm trying to do. In short, there are different constructors for different dom elements, and they don't seem to all share a common prototype. I'm looking for a way to add a function property to every DOM element…
Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
4
votes
2 answers

vba, getElementsByClassName, HTMLSource's double quotation marks are gone

I scrape some websites with vba for fun and I use VBA as tool. I use XMLHTTP and HTMLDocument (cause it's more faster than internetExplorer.Application). Public Sub XMLhtmlDocumentHTMLSourceScraper() Dim XMLHTTPReq As Object Dim htmlDoc As…
Soborubang
  • 43
  • 1
  • 6
4
votes
4 answers

Changing innerHTML to value from div's Id captured by it's ClassName

I have some buttons 1-9 and i want to show their numbers on div called "screen". So i wrote such code, but it not seem to work. Piece of HTML code with those buttons:
4
votes
4 answers

Get value of HREF for links within a certain Class in Javascript

I'm trying to process a page to find the value of href's within a certain div class. Please bear in mind I'm not using the class of the . Here is what I have: var domains = document.getElementsByClassName('r'); for(var i = 0; i < domains.length;…
4
votes
2 answers

How can i get elements by class instead of "GetElementById"?

So, this is the code: URL: