user3112634
user3112634

Reputation: 693

If div text equals certain text do something?

Cannot for the life of me get this to work. Even when removing the AJAX POST function, it still doesn't work. There is no alert or anything. Here is the JSFiddle and code:

HTML

<div class="notification">
            <div class="title gooddog">test</div>
            <div class="reason helvetica"></div>
        </div>
<script>
    var interval = setInterval(function(){

      var Winner = $(".notification .title gooddog").text();
      if(Winner == "test") {
        $.ajax({
          url: "Won.php",
          type: "POST",
          data: { Winner : Winner }
        })
        .success(function(data) {
          console.log('foo', data);
        });
      }

    },1000);
</script>

It is meant to trigger/check the div text for changes every 1 seconds, but as you can see, it's doing nothing..

Upvotes: 0

Views: 383

Answers (2)

Leo
Leo

Reputation: 14850

You've got several issues...

  1. You are using jQuery syntax but you are not including the jQuery plugin...at least not in the fiddle

  2. Not an issue in this case, but if you want to get whatever is inside a div use the html function rather than the text function

  3. As @Cattla pointed out in her answer to the proper "multi-class" selector is .title.gooddog

I wouldn't be surprised if you had more issues on the server-side as well. Here's an updated JS Fiddler

Upvotes: 0

Alien
Alien

Reputation: 3678

var Winner = $(".notification .title gooddog").text();

should be

var Winner = $(".notification .title.gooddog").text();

jsfiddle http://jsfiddle.net/abwp5u21/8/

Upvotes: 1

Related Questions