开发者

Jquery:Content search error

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜