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
10
votes
3 answers

Struggling with classList.add and getElementsByClassName

I'm trying to add a extra class to some elements with a specific class(input-fieldset).
So I did some searches and found this: var…
aproskam
  • 121
  • 1
  • 1
  • 10
9
votes
3 answers

Change value attribute by class via JavaScript

I have the following HTML: I need JavaScript that will change the value of "account" to "yolo". I thought I could do…
Cagey215
  • 159
  • 1
  • 1
  • 8
9
votes
2 answers

Get elements with one class but not another without iterating

In the following simple HTML, I would like to get all elements with class1 but not with class2.
  • By using getElementsByClassName('class1') we could get…
    mavrosxristoforos
    • 3,573
    • 2
    • 25
    • 40
    7
    votes
    2 answers

    getElementsByClassName doesn't work, but getElementById does?

    I've written a script, it's goal is to stop displaying images one and two, while allowing image 3 to remain displayed and move into their place. It works fine when I use div Id's instead of div Classes, but I would prefer to use div classes so I can…
    Jack Elwell
    • 99
    • 1
    • 1
    • 6
    7
    votes
    6 answers

    How to add image to button via Javascript?

    I am trying to add image to buttons I have using Javascript but I can't seem to get it working. I have sucessfully added image using HTML5, however, for my needs I need to add the image via javascript. Below is what I have written to add images via…
    Henry
    • 1,042
    • 2
    • 17
    • 47
    7
    votes
    3 answers

    Disable text box using class name in Javascript

    I have HTML Name 1: Javascript function disfunction(){ document.getElementsByClassName("one").disabled = true; } But the text box is still enabled. How can I…
    Deepu Sasidharan
    • 5,193
    • 10
    • 40
    • 97
    6
    votes
    2 answers

    remove p element from DOM tree with javascript

    This should be a simple one, and yet I need help to solve the problem: I need to remove the element with the class "goup" on it from the DOM tree with javascript (eventually with prototype, but no other library). I don't only want to hide that…
    AKnox
    • 63
    • 1
    • 2
    • 4
    5
    votes
    2 answers

    Is it possible to getElementsByClassName with partial name on Vanilla Javascript?

    I need to get all innerText of all elements that partially match a given string. Heres a snippet of the code: Some text The class always ends with 'sarasa' the numbers are dynamic. I want to run it on a chrome…
    5
    votes
    6 answers

    getElementsByClassName IE resolution issue

    I am having issues figuring out how to resolve the getElementsByClassName issue in IE. How would I best implement the robert nyman (can't post the link to it since my rep is only 1) resolution into my code? Or would a jquery resolution be better?…
    Ryan Sharp
    • 153
    • 1
    • 1
    • 5
    5
    votes
    2 answers

    .innerHTML is not a function

    Its so plain simple, I can not comprehend, what is the issue? All DOMs are created before I pick them, used either a document.getElementsByClass or just the dom object created itself, not working... I wonder where did I do wrong? var wrapperDom…
    ey dee ey em
    • 7,991
    • 14
    • 65
    • 121
    5
    votes
    6 answers

    Javascript remove not removing all elements

    Please refer fiddle - http://jsfiddle.net/fkwwyvz8/ x = document.getElementsByClassName("buddy_blocks"); for(i=0;i
    nikhil rao
    • 381
    • 3
    • 6
    • 9
    5
    votes
    3 answers

    addClass to getElementsByClassName array

    I need a little help as i am getting frustrated with .getElementsByClassName. I have an svg map that has paths with classes. I now need to list all with a certain class and add another class. Right now i have var testarray =…
    Mind_meddler
    • 121
    • 1
    • 2
    • 10
    5
    votes
    3 answers

    pull data from website using VBA excel multiple classname

    I know this has been asked many times, but haven't seen a clear answer for looping thru a div and findind tags with the same classname. My first question: If I have something like this:
    5
    votes
    4 answers

    Get Element By Classname Script Not Working

    I know, it's not supported by IE, but I found a cool script online that someone was generous enough to provide for free, but I can't figure out why it's not working. I've been staring at this for hours, please point me in the right direction! My…
    I wrestled a bear once.
    • 22,983
    • 19
    • 69
    • 116
    4
    votes
    6 answers

    getElementsByClassName returns [] instead of asynchronous appended node

    (I ask my question again after the first one was terribly formulated) I face the following problem:
    The above written element is predefined. I now load a xml tree via XMLHttpRequest & Co. delivering the…
    Leo Selig
    • 1,062
    • 1
    • 16
    • 30
    1
    2
    3
    44 45