domino
domino

Reputation: 7345

jQuery if not '0'

$(".test").css('cursor','pointer');
<div class="test>0</div>
<div class="test>1,000</div>

How do I apply this to the elements that are not 0?

Upvotes: 3

Views: 2257

Answers (4)

thecodeparadox
thecodeparadox

Reputation: 87073

$(".test").filter(function() {
   return this.innerHTML != '0';
}).css('cursor','pointer');

DEMO

Correction to your HTML

<div class="test">0</div>  <!-- missing closing quote-->
<div class="test">1,000</div> <!-- missing closing quote-->

Upvotes: 3

Undefined
Undefined

Reputation: 11431

You can use some thing like this:

if($(".test").text() != '0')
  {

     //Your code here   

  }

By using .text() it will get the text from the selector (as you may have imagined)

Upvotes: 0

romainberger
romainberger

Reputation: 4558

$('.test').each(function(){
    if($(this).text() != '0')
        $(this).css('cursor', 'pointer');
});

But the easiest would be to add a different class

Upvotes: 0

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

If i assume correctly, you want cursor:pointer to be applied to div with contents that are not 0. Try using filter like below,

$('.test').filter(function () { 
      return $(this).text() != '0'; 
}).css('cursor', 'pointer');

Upvotes: 1

Related Questions