:contents() CSS3 selector support

17 views
Skip to first unread message

xaguilars

unread,
Mar 14, 2010, 2:38:35 PM3/14/10
to RightJS
Hello I'm trying to perform a conditional selection for implementing a
table/row search engine using RightJS.
I come from jQuery and this was very easy: $("#datagrid1 > tr
> .description:contains('"+str+"')");
But when I use the :contains() selector in RightJS it throws an error
(illegal string).

How can I implement this?

Thank you!

xaguilars

unread,
Mar 14, 2010, 2:39:41 PM3/14/10
to RightJS
Can we extend the CSS selectors in RightJS?

MadRabbit

unread,
Mar 14, 2010, 3:21:37 PM3/14/10
to RightJS
Hey man,

RightJS uses browser native css selectors, and although you might
find :contains in specs, modern browsers don't support this feature,
so doesn't RightJS.

jQuery emulates this pseudo-selector along with some others.

With RightJS you can have about the same result using Array#filter
method, kinda like that

$$('my rule').filter(function(td) { return
td.innerHTML.includes(my_string); });

It is certainly a bit longer, but generally does exactly the same
thing.

There are also plans for implementing a plugin with additional CSS
features, but it won't happen soon.

--
Cheers,
Nik

xaguilars

unread,
Mar 14, 2010, 4:01:41 PM3/14/10
to RightJS
Thank you very much, I've done an approach for the functionality that
I need:

window.$$filter=function(selector, regexp, negative){
negative = negative || false;
return $$(selector).filter(function(element){
if(/input/i.test(element.tagName)){
if(negative==true) return
regexp.test(element.value)==false;
else return regexp.test(element.value)==true;
}else{
if(negative==true) return
regexp.test(element.innerHTML)==false;
else return regexp.test(element.innerHTML)==true;
}
});
}
document.onReady(function(){
//This will hide all the TR's that don't have TD's containing
'lorem ipsum'
$$filter('td', /lorem ipsum/,
true).each('parent','tr').each('hide');
});

Vic Khomyackov

unread,
Oct 29, 2011, 12:42:43 PM10/29/11
to rig...@googlegroups.com

            if(negative==true) return
regexp.test(element.value)==false;
            else return regexp.test(element.value)==true;

:)

return (regexp.test(element.value)==!negative);

Nikolay Nemshilov

unread,
Oct 29, 2011, 2:57:55 PM10/29/11
to rig...@googlegroups.com
smarty pants :)

--
Thanks,
Nikolay

Reply all
Reply to author
Forward
0 new messages