[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

jquery select td text

Posted on 2011-04-27
8
Medium Priority
?
634 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:Solutionabc
  • 5
  • 2
8 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 35477148
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
 

Author Comment

by:Solutionabc
ID: 35477299
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
 
LVL 83

Expert Comment

by:leakim971
ID: 35477364
With :
<div id="test">187</div>

Open in new window

$("#test").text() return 187
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Expert Comment

by:Proculopsis
ID: 35477449

// In your change function:

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

// should do it.
0
 

Author Comment

by:Solutionabc
ID: 35477456
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
 
LVL 83

Expert Comment

by:leakim971
ID: 35477526
except I need to be able to get the next next next .text()

following the node or inside it?
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 35477536
>$("#test").text() because it grabs all of them

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

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 35505388
Thanks for the points!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month20 days, 9 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question