jquery select td text

I have a table with multiple cells that have a div with a number that I want to compare. I am already doing some comparision inside of the input title="orderQty" that is successful but now I need the inner text value of the div to compare.

I have multiple cells so I cannot just grab like $("#test").text() because it grabs all of them (I only want the next test div's inner text)

My table cell:

<td class="orderQty">
<SPAN><INPUT  title="orderQty" /></span>
<SPAN><INPUT /></span>
<SPAN><INPUT /></span>
<div id="test">187</div>
<SPAN><INPUT /></span>
</td>

thank you
//This is what I have this far: 
$(".orderQty span INPUT").change(function(){
if ($(this).val() > $("#test").text()){
           $(this).val("good");
           } else {
           $(this).val("bad");
           }
});

Open in new window

SolutionabcAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
>$("#test").text() because it grabs all of them

ok use :
$(this).parent("td").find("#test").text();

Open in new window

0
 
leakim971PluritechnicianCommented:
Assuming you've multiple container (generaly a div) :

<div id="test"><div><div>187</div></div></div>

Open in new window


you may use : $("#test div:last").text()
0
 
SolutionabcAuthor Commented:
I do not have multiple containers, it is just a div with a value inside.

is $("#test").text() only suppose to grab the nearest divs value? or grab all of them?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
leakim971PluritechnicianCommented:
With :
<div id="test">187</div>

Open in new window

$("#test").text() return 187
0
 
ProculopsisCommented:

// In your change function:

  alert( $(this).closest("td").find("div").text() );

// should do it.
0
 
SolutionabcAuthor Commented:
I think I need to be able to traverse through the dom. I am successfully referencing the first input element then from there I need to move down to the nearest div to grab the value.

something like:
$(this).next();

except I need to be able to get the next next next .text().
0
 
leakim971PluritechnicianCommented:
except I need to be able to get the next next next .text()

following the node or inside it?
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.