JQuery - innerText starts with a selector broken into

Just upgraded from jQuery 1.3.2 to 1.8.2 and found that several functions that worked in version 1.3.2 no longer work. I fixed most of them, but got stuck on this:

I need to search based on the first few characters in a table cell (the search "starts with"), but this code no longer works in recent jQuery versions:

var matchingElements = $("#tblSelect1>tbody>tr>td:first-child[innerText^='" + text + "']"); 

I suspect this has something to do with the fact that a few things that used to work as attributes are now properties - innerText is a property (I think), and maybe it's not compatible with running an attribute - using the notation selector: [attr^='value']

I don’t want to use :contains because I only need elements whose intTextText starts with a text search

Thoughts? Thanks!

+4
source share
1 answer

You can use the filter method. innerText is a non-standard property and does not work in Firefox, to support all major browsers you should check both properties or use the jQuery text method, which is a cross-browser.

 var $matchingElements = $("#tblSelect1 > tbody > tr > td").filter(function(){ var c = this.textContent || this.innerText; return c.indexOf(text) === 0 }); 
+3
source

All Articles