Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jQuery find and contains

Posted on 2014-12-10
7
153 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
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.

 

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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?
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…

838 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