Answer the question
In order to leave comments, you need to log in
how to do pattern search in jquery
I'm building a tree in jquery, I've learned how to add a child, but it's still a problem with siblings. For brothers, you need to somehow look for it in the pattern. For example, at best
$('body').find('[data-for-tree="some[closure][0][closure][\\d]]"')
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
},
regexFlags = 'ig',
regex = new RegExp(matchParams.join('').replace(/^s+|s+$/g,''), regexFlags);
return regex.test(jQuery(elem)[attr.method](attr.property));
}
$(' :regex(data-for-tree,/some\[closure\]\[\d\]/)')
Answer the question
In order to leave comments, you need to log in
<div data-for-tree="some[closure][1]">child 1</div>
<div data-for-tree="some[closure][2]">child 2</div>
$(':regex(data-for-tree,some\\[closure\\]\\[\\d\\])')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question