Source: Regex match string until whitespace Javascript.
Une regex qui extrait, à partir d’une chaîne de caractères de type level1 nav-1-1 category-item first active parent is-submenu-item is-drilldown-submenu-item
la classe qui commence par nav-
et se termine au prochain espacement (whitespace):
1 2 3 4 5 6 7 8 9 |
$('.level1', '#megaMenu').on('click', function(e){ e.preventDefault(); let $_THIS = $(this); $_THIS.removeClass(function () { // Select the element divs which has class that starts with "nav-" var className = this.className.match(/(nav-)[^\s]+/gi); // Get a match to match the pattern "Starts with nav- and until next whitespace" and extract that classname console.log(className); // ["nav-1-1"] }); }); |