Solved

jQuery find and contains

Posted on 2014-12-10
7
152 Views
Last Modified: 2014-12-10
Hello Experts,

I am trying to:

1. Find the TD in a table that its text is equal to the "loftNo" variable.
2. Then go to the next TD and grab its text.

Help! Today my brain doesn't work!!!!


$('area').each(function() {
     var loftNo = $(this).attr("id");
    var LoftType = $("td:first:contains("+loftNo+")").next().text();

Open in new window

0
Comment
Question by:Refael
  • 4
  • 2
7 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40491964
try this:

$("table td[text='" +leftNo + "']").next().text()
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40491981
here is a working sample, giving "b"

<table>
    <tr><td>test</td><td>001</td><td>a</td></tr>
    <tr><td>test</td><td>002</td><td>b</td></tr>
    <tr><td>test</td><td>003</td><td>c</td></tr>
 <table>

...

var leftNo = "002";
alert($("table td").filter(function() { return $.text([this]) == leftNo; }).next().text());

Open in new window

0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40491990
just make sure you pass unique values... if you pass "002" and we have 2 td, texts are joined :)
if i change my 3rd row td value to "002" and try that code, I will get "bc"
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Refael
ID: 40492005
Hi Huseyin KAHRAMAN :-) Thank you.

I think the problem was that i was searching on the first TD only. So I have changed it to "nth-child" and it looks that it is working fine. Yes filter would work better when dealing with duplicate values.
 $("td:nth-child(1):contains("+loftNo+")").next().text(); 

Open in new window

0
 

Author Closing Comment

by:Refael
ID: 40492008
Thank you Huseyin KAHRAMAN :-))
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40492009
oops, my nick should be "HainKurt" :) I made a mistake and put my f&l name somewhere...

fixed it by removing First & Last Name on profile page :)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40492028
please provide a link to your website
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What am I doing wrong with this Lightbox widget? 6 34
HTML5 frame 5 25
Jquery 10 20
Jquery Validation Messages Not Showing Up 3 9
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 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