JavaScript getElementsByCustomTag ('value')?

I know getElementsByName ("something") that returns elements with name = "something", but I want to return a list of elements where custom = "something", how would I do it?

+3
source share
3 answers

To answer my own question, it seems to have been easier than I thought.

elements = document.getElementsByTagName('pre');

for (elem = 0;elem < elements.length;elem++)
 {
  element = elements[elem];

  if (element.lang != 'php')
   break;
  ...
 }

The above happened in my situation. :)

+1
source

There is no standard API in the DOM.

If you don't mind adding jQuery to your project, you can query your elements using the jQuery attribute selector:

$("[custom='something']")
+1
source

Document JavaScript, . , getElementById(), getElementByName() getElementByTagName().

I think you need to use something like jQuery to get more freedom, as it allows you to express more complex " queries ". I'm not sure, but it can be slower, depending on how often you have to look for things.

0
source

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


All Articles