gwtcss-selectorsgwtquery

Does GWTQuery support the CSS Selector [attr*="some_val"]?


I have been using GQuery for a while now. I recently came across some unexpected behaviour.

I have 2 different scenarios:

a) I want to select an element say

<a href="http://example.com?p=site:helloworld.com">Link</a>

I used

GQuery.$("a[href*=site:helloworld.com]") 

This doesn't seem to work.

b) The other thing I wish to select is

<h1 data-title="SampleTitle">Title</h1>

I need to extract the value of data-title. I used the following:

GQuery.$("h1").attr("data-title");

Now, this doesn't return an error but it doesn't return the value either. It just returns a blank String. This doesn't have anything to do with the '-', is it?

What am I doing wrong here?


Solution

  • a) I did a quick test, and the selector works fine! (But you have to quote the value as mentioned in another answer: GQuery.$("a[href*=\"site:helloworld.com\"]"))

    Note: The "*=" selector is defined in CSS 3. Gwtquery usually only supports CSS 2 at the moment, see http://code.google.com/p/gwtquery/wiki/CssGuide#CSS_scope

    b) GQuery.$("h1").attr("data-title"); works for me: It returns the full attribute string value of the first "h1" element in the document

    I'm using gwtquery 1.1.0 + GWT 2.4.0. If possible, try to upgrade to these (or later) versions.