Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you mean like:</p> <pre><code>var elementArray = document.getElementsByName("/regexhere/"); </code></pre> <p>then no that would not be possible.</p> <p>To do what you want to do you would have to get all the elements, then go through each one and check the name of it.</p> <p>Heres a function that will go through all the elements and add all the elements with a certain name to an array:</p> <pre><code> function findElements(name) { var elArray = []; var tmp = document.getElementsByTagName("*"); var regex = new RegExp("(^|\\s)" + name + "(\\s|$)"); for ( var i = 0; i &lt; tmp.length; i++ ) { if ( regex.test(tmp[i].name) ) { elArray.push(tmp[i]); } } return elArray; } </code></pre> <p>And use as:</p> <pre><code>var elName = "customcontrol"; var elArray = customcontrol(elName); </code></pre> <p>Or it might be easier by className</p> <pre><code> function findElements(className) { var elArray = []; var tmp = document.getElementsByTagName("*"); var regex = new RegExp("(^|\\s)" + className+ "(\\s|$)"); for ( var i = 0; i &lt; tmp.length; i++ ) { if ( regex.test(tmp[i].className) ) { elArray.push(tmp[i]); } } return elArray; } </code></pre> <p>And use as:</p> <pre><code>var elClassName = "classname"; var elArray; if (!document.getElementsByClassName) { elArray= findElements(elClassName ); } else { elArray = document.getElementsByClassName(elClassName); } </code></pre> <p>This would do what you want, without the need for getElementByName.</p> <p>Although I think you meant getElementsByName</p> <p>If you wanted to look for an element with only the name "customcontrol" you would use:</p> <pre><code>var regex = new RegExp("(^|\\s)" + name + "(\\s|$)"); </code></pre> <p>If you wanted to look for an element with that STARTED with the name "customcontrol" you would use:</p> <pre><code>var regex = new RegExp("(^|\\s)" + name); </code></pre> <p>EDIT:</p> <p>If your using jQuery, which would be easier, then this would do:</p> <pre><code>var elArray = $("*[name^='customcontrol']"); //Use JavaScript to loop through for (var a = 0; a&lt; elArray.length;a++) { //Loop through each element alert(elArray[a]); } //Or $("*[name^='customcontrol']").css("color","red"); //Or whatever you want to do to the elements </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload