mod geek
mod geek

Reputation: 310

How To compare the Value Of The Div In jQuery

I would appreciate If somebody help here! . I want to compare the value of the div from the php array using jQuery.

I have a php array

$newarray=array('cat','cap','catm','cam','catp','camp');

i have assigned a class 'turn' too all the php array members

foreach($newarray as $col){
        echo "<p class='turn'>".$col."</p>";    
}

Now I want to check the value of the div and compare that if value in the textbox is equal to arrays value or not.

I have given the myBox id to the div

and this is my jQuery Code

    $(".wordComb").click(function(){

    $(".turn").each(function(i,e){
myDivObj = $('#myBox').text();
        if(myDivObj == e)
        {
                alert("Wow !!");
        }
        else{
            alert("try Again !");
        }
    });

    });

Upvotes: 1

Views: 1219

Answers (1)

Peter van der Wal
Peter van der Wal

Reputation: 11796

if (myDivObj == e) {

should be

if (myDivObj == $(e).text()) {

since e is the p.turn HTML-element

jsFiddle example

Upvotes: 3

Related Questions