mod geek mod geek - 7 months ago 7
Javascript Question

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 !");
}
});

});

Answer
if (myDivObj == e) {

should be

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

since e is the p.turn HTML-element

jsFiddle example

Comments