开发者

Jquery:Content search error

开发者 https://www.devze.com 2023-03-27 08:27 出处:网络
I have a problem a开发者_C百科bout searching a text. I think it is Ja because of the whitespaces

I have a problem a开发者_C百科bout searching a text. I think it is Ja because of the whitespaces

This is my script that working.

$('td > a:contains("Hallow")').each(function(){
    if($(this).parent().next('td').text() == 'Secured') {
      alert("working well")
    }
    else {
      alert($(this).text());
    }
});

There is no whitespaces and my script is working : http://jsfiddle.net/FrE9Q/7/

<td width="140" align="right">Secured</td>

There is no whitespaces


Here is real html with whitespaces and my script isnt working: http://jsfiddle.net/FrE9Q/8/

        <td width="140" align="right">
        Secured
    </td>

Whitespaces...

Thank you for your helps.


Then remove trailing and leading white spaces, using $.trim [docs]:

if ($.trim($(this).parent().next('td').text()) === '...')


Use $.trim()

$('td > a:contains("Hallow")').each(function() {
    var text = $(this).parent().next('td').text();
    if ($.trim(text) == 'Secured') {
        alert("working well")
    }
    else {
        alert($(this).text());
    }
});

Fiddle: http://jsfiddle.net/maniator/FrE9Q/9/

0

精彩评论

暂无评论...
验证码 换一张
取 消