Iladarsda
Iladarsda

Reputation: 10692

:contains issue on IE8

It seems that jQuery :contains selector does not work on IE8.

Please see following example on IE - LIVE DEMO

JS:

$('table tr td:contains(" + ")').each( function(){
        $(this).addClass('url');
});

Upvotes: 3

Views: 922

Answers (2)

Iladarsda
Iladarsda

Reputation: 10692

Another simpler solution to the IE8 :contains issue:

Make sure you are not using the space inside the string, e.g

$('table tr td:contains("+")') will work even if your html have spaces<td> + </td>

Upvotes: 0

Pierre
Pierre

Reputation: 19081

You need to convert the spaces in your TDs to HTML entities (&nbsp;)

for $('table tr td:contains(" + ")') to work. (Same JS/CSS)

HTML:

<table>
    <tr>
         <td>&nbsp;+&nbsp;</td>
         <td> 1 </td>
         <td> 3 </td>
         <td> 6 </td>
         <td> 7 </td>
    </tr>
</table>

However it will fail on modern browsers, so the solution is to replace the entities for those browsers. Just prepend this snippet before yours, it will do the job.

if( !($.browser.msie && $.browser.version < 10) ){
    $('table tr td').each(function(){
        $(this).html( $(this).html().replace(/&nbsp;/gi, ' ') );
    });
}

Upvotes: 4

Related Questions