Solved

jquery text contain find

Posted on 2012-04-09
4
368 Views
Last Modified: 2012-04-09
Hello Experts,

Here is what i am trying to do.... hopping someone will correct me :-)

TASK:

Check if the text in the second TD (table column) starts with "xyz".


var secondTd = $('td.eq(2)', $(this));
	
        if (secondTd.length == 0)
	return;
		
	   var text = secondTd.text();	
		
		if (text == "xyz") {
		//do something....................		
		} 
                 else {

                        } // do something else

                 }
           

Open in new window

0
Comment
Question by:Refael
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37825370
Assuming that your table is something like this:-
<table id='tblTest'>
        <tr>
            <td>abc</td>
            <td>xyz</td>
            <td>are</td>
        </tr>
    </table>

Open in new window

Here is the jquery for comparison:-
$('#tblTest tr td:nth-child(2)').text() == "xyz"

Open in new window

0
 

Author Comment

by:Refael
ID: 37825442
Hi BuggyCoder,

that's wrong because you check if the entire TD text string is equal ... and i am after the beginning of the string or if its easier then i can use "contain".

Here is my code again..... if you can just tell me where the problem is:


var secondTd = $('.tdlight:eq(1)', $(this));
		
		if (secondTd.length == 0)
		return;	
			
		var text = secondTd.text();
		
		alert (text);
		
		if ($(this).text() == "2. FLOOR") {
			
		$('#ausblicke-etagen').show()
		}

Open in new window

0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37825456
here is the code that will check if the text of td starts with xy:-

var txt = $('#tblTest tr td:nth-child(2)').text();
if(txt.indexOf("xy")>=0)
{
//Yes the text starts with xy
};
0
 

Author Closing Comment

by:Refael
ID: 37825508
Great, that's what i was looking for :-)
0

Featured Post

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.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now