Sunday, 15 June 2014

javascript - js Search String and get matched elements -



javascript - js Search String and get matched elements -

i want inquire best way search string , matched element?

//i want similar or matched element , index of it. //search key ward var key = 'pap'; <ul> <li>papa</li> <li>mama</li> </ul>

my thought utilize $.each , match text of each, believe should wrong way. however, couldn't find references net question.

thank much.

use :contains selector

$('*:contains("'+key+'"):last')

to find exact match whole text in element utilize this

$.fn.exactmatch = function (key) { var p = $(this).find(':contains("' + key + '"):last'); if (p.text() == key) { p.css('background', 'yellow'); } else { //not exact match function if wanted } }

to utilize function this

$(el).exactmatch(key);

javascript jquery string search match

No comments:

Post a Comment