Link to home
Start Free TrialLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

jquery text contain find

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

Avatar of BuggyCoder
BuggyCoder
Flag of India image

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

Avatar of Refael

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Refael

ASKER

Great, that's what i was looking for :-)