1

I am newbie in both JS and Sizzle, trying to implement a system that generates links according to a keyword like Google AdSense do. I ve searched and decided to use Sizzle CSS Selector for this.

I have an html document and a keyword, I want to search "all keywords which are not in a link ( tags).

My Sample HTML part

<div> <p>... some text .... 
    ....................................
    <strong>......keyword......</strong>
    ....................................
    ...........................keyword..
    ....................................
</p>  </div>

I used ":contains" selector to search this keyword in JS and used document body as search context. After search results I will replace the elements with some link(keyword).

Sizzle(":contains(keyword)", document.body);

It returns me an array contains "div, p, strong" elements. There is 2 "keyword" s in the context both it returns parent elements of results (div is unnecessary here).

Is there any usage of Sizzle to prevent this problem?

An extra question: I searched Sizzle selectros, also w3c selectors. ":not" selector is used to get negative given selector. How can I see the element is not in a link tag without traversing dom with "parentElement" attribute(I mean with sizzle selectors considering the link tag can be upper parent nodes of element).

Thanks.

prince
  • 854
  • 2
  • 9
  • 36
Sinan Goker
  • 249
  • 1
  • 3
  • 16
  • This is one major problem with `:contains()` causing it to be removed from the CSS spec. It just didn't fly with ancestor elements. – BoltClock Apr 17 '12 at 11:09
  • So will the solution be -get elements with :contains() -check each element if it's ancestor element exists -if exists, drop the ancestor element I ve tried this solution but I think it has a high cost( m: # of elements, n: depth,) It has a **m^2 * n** complexity. Would it be a good implementation for this or any better solution? – Sinan Goker Apr 17 '12 at 13:17

0 Answers0