jquery - Checking content with inArray to add class -


so jquery "inarray" new beast me little unsure how this'll work. https://api.jquery.com/jquery.inarray/

i have div content "0 checkout now".

i check when 0 changes number, if change add class of "active" containing div.

my html looks this:

<div class="search-again-panel-top">     <a class="checkout-now" href="#">     0 checkout     </a> </div> 

this tried do:

$('.search-again-panel-top .checkout-now').filter(function() {         var text = $(this).text('0');         return $.inarray(text, this) = -1;     }).addclass('active'); 

you try this:

var checkelement = $('.search-again-panel-top .checkout-now') var parts = $(checkelement).html().split(" "); if (jquery.inarray("0", parts) == -1) { //do nothing } else { //has changed $(checkelement).addclass("active"); } 

the jquery.inarray function passes item searching first parameter, , actual array checking in second parameter , checks if exists. if item found in array return character position in string found in. if not found, return -1


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -