I did something similar (again on my dog's site) http://jpassoc.com/junior/story/ I wrote a couple of plugins to hook into the text of a page (in my case loaded via $.get) and diddle with the the class and add some clicks. http://jpassoc.com/js/jquery-kidsbook.js
this is 'hook' jQuery.fn.hook=function(hash){ var fix = function(text,hash){ var t = text.split(/\b/) var inTag = false for (var i = 0; i < t.length; i++){ var wd = t[i] if (wd.match(/^\s*$/)) continue if (wd.match(/</)) inTag = true if (wd.match(/>/)) inTag = false if ( !inTag && hash[wd] || hash[wd.toLowerCase()] ) { t[i] = "<span class='hooked'>" + wd + "</span>" //$.log("hooked " + wd) } } return t.join("") } this.each(function(){ $(this).html(fix($(this).html(),hash)) }) return jQuery('span.hooked',this) } On 4/13/07, Sebastián V. Würtz <[EMAIL PROTECTED]> wrote:
Im trying to make a "highlight text from search" script wich must load the "keyword" saves into a hidden field, but cant make it work, i found some script in the web but dosnt adjust to what i need if any1 can helpme what wrong here i apreciate. I just modify it a little i know now is not working but is that the idea. $(document).ready(function(){ var matches = $("input#i_search_keywords").attr("value"); if (!matches) return; matches = split(",", matches); var terms = unescape(matches[1].replace(/\+/g, ' ')); var re = new RegExp().compile('(' + terms + ')', 'i'); $("body *").each(function() { if ($(this).children().size() > 0) return; if ($(this).is("xmp, pre")) return; var html = $(this).html(); var newhtml = html.replace(re, '<span class="qterm">$1</span>'); $(this).html(newhtml); }); }); Example of hidden input <input type="hidden" value="new awesome game , awesome, game" id="i_search_keywords" name="i_search_keywords"/> Sry for my english
-- Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ