Iterate targeting names with JS

I am trying to parse JSON data in concrete iterations of the class name "slide_content"

To get something like this:

slide_content[0]

But JS does not provide a selector getElementByClass().

The API data is here: Converting JS Directs to JQuery

Hooray! Miles

+1
source share
2 answers

Use jQuery. It allows you $('.someClass')to use to retrieve all elements with a given class name.

jQuery JS- - , Sizzle, jQuery - , JS ( , : p). jquery, , jQuery...

+1

(IE9 ) document.getElementsByClassName ( , , querySelectorAll, ...), , , t . - , .

var nodes = document.getElementsByTagName('*'),
    targetClass = 'myclass',
    result = [];

for(var i = 0, l = nodes.length; i < l; i++){
    if((nodes[i].className + ' ').indexOf(targetClass + ' ') !== -1){
        result.push(nodes[i]);
    }
}

getElementsByClassName, NodeList, .

+2

Source: https://habr.com/ru/post/1787480/


All Articles