Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - find a pattern anywhere in a string?

I still get a little confused when it comes to selectors and patterns... Basically, I'm trying to find the parent div of an input item and if a string is found anywhere in its ID, I want to set it to display none.

I've done this before by just doing something like:

if($('div[id*=string]')) { $(this).attr('display','none'); }

But, I'm not sure how to do that for a variable?

This is as far as I got, and then I get stuck...

$('input.rclass').each(function() {
    var myDiv = $(this).parent().parent();
    if($(myDiv...
});

The markup looks like this:

<div id="edit-gci" class="form-item">
   <label for="editgci[0][foa][value]" class="option">
     <input type="radio" class="rclass" value="" name="editgci[0][foa][value]" id="editgci-0-value-string-idnum"> N/A
   </label>
</div>
like image 967
KarmaKarmaKarma Avatar asked Jan 20 '26 08:01

KarmaKarmaKarma


1 Answers

The attr is used for setting element's attributes, so your line:

if($('div[id*=string]')) { $(this).attr('display','none'); }

Should be:

if($('div[id*=string]')) { $(this).css('display','none'); }

Use css method instead.

like image 153
Sarfraz Avatar answered Jan 21 '26 23:01

Sarfraz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!