“Wild Card Queryselector” Réponses codées

Wild Card Queryselector

// basically, of before:
var youtubeDiv = document.querySelector('iframe[src="http://www.youtube.com/embed/Jk5lTqQzoKA"]')

// after     
var youtubeDiv = document.querySelector('iframe[src^="http://www.youtube.com"]');
// or even, for my needs
var youtubeDiv = document.querySelector('iframe[src*="youtube"]');
ammer

Wild Card Queryselector

/**
 * Find all the elements with a tagName that matches.
 * @param {RegExp} regEx  regular expression to match against tagName
 * @returns {Array}       elements in the DOM that match
 */
function getAllTagMatches(regEx) {
  return Array.prototype.slice.call(document.querySelectorAll('*')).filter(function (el) { 
    return el.tagName.match(regEx);
  });
}
getAllTagMatches(/^di/i); // Returns an array of all elements that begin with "di", eg "div"
ammer

Réponses similaires à “Wild Card Queryselector”

Questions similaires à “Wild Card Queryselector”

Plus de réponses similaires à “Wild Card Queryselector” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code