Solved

jQuery find and contains

Posted on 2014-12-10
7
154 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 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 40491964
try this:

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

Accepted Solution

by:
Huseyin KAHRAMAN 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 52

Expert Comment

by:Huseyin KAHRAMAN
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 52

Expert Comment

by:Huseyin KAHRAMAN
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
email validation 9 51
testing a web application for ipad on windows pc 3 41
javascript form - error when hitting enter 3 28
Can anyone help me find this preloader? 51 47
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

730 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