JavaScript search function is also searching html code -



JavaScript search function is also searching html code -

i want utilize html tags within answers section when code pulling through when using search. have little experience javascript advice helpful

javascript

$('h3.topic').click(function () { $(this).next().toggle(300); }); $('h4.question').click(function () { $(this).next().toggle(300); }); $('#expandall').click(function () { $('#faq').children('div.topiccontents').show(300).children('div.answer').show(300); }); $('#collapseall').click(function () { $('#faq').children('div.topiccontents').hide(300).children('div.answer').hide(); }); jquery.expr[':'].contains = function (a, i, m) { homecoming jquery(a).text().touppercase().indexof(m[3].touppercase()) >= 0; }; $('#searchfaq').click(function () { $('#faq').children('div.topiccontents').hide().children('div.answer').hide(); if ($('#faqsearch').val() != '') { $('div.answer:contains(' + $('#faqsearch').val().touppercase() + ')').show().parent().show(300); seek { $('.highlight').removeclass("highlight"); $('div.answer:contains(' + $('#faqsearch').val().touppercase() + ')').each(function () { $(this).html( $(this).html().replace( new regexp($('#faqsearch').val(), "ig"), function (match) { homecoming '<span class="highlight">' + match + '</span>'; } ) ) }); } grab (err) {} } homecoming false; });

try replacing new regexp($('#faqsearch').val(), "ig") new regexp('(' + $('#faqsearch').val() + ')(?![^<]*>)', "ig").

demo: http://jsfiddle.net/4pwrj/

var $searcharea = $('#search-area'); $('input').keyup(function () { var value = this.value.trim(), rx; $searcharea.find('.highlight').each(function () { this.parentnode.replacechild(document.createtextnode(this.textcontent), this); }); if (!value) return; rx = new regexp('(' + this.value + ')(?![^<]*>)', "ig"); $searcharea.html($searcharea.html().replace(rx, '<span class="highlight">$1</span>')); });

javascript search accordion

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -