jQuery and XPath

G

Gale

I'm working on something in jQuery with XPath

What I want to do is: if checkbox is checked, set background color od
label that contain input(checkbox) to red

I have this code:
$("label[input[@checked]]").css("background", "red");

but it doesn't working because of nested brackets [[ ]] and it freeze
the browser
In Xpath documentation say it can be used

any sugestions?
 
V

VK

Gale said:
I'm working on something in jQuery with XPath

So how or anyhow is that related to JavaScript/JScript? Neither of both
atop are connected with it.

For JavaScript solution ask here (will be glad to help), for XPath
solution ask at <comp.text.xml>, for jQuery plugin ask at some Eclipse
forum.
 
A

Abba.Bryant

VK said:
So how or anyhow is that related to JavaScript/JScript? Neither of both
atop are connected with it.

For JavaScript solution ask here (will be glad to help), for XPath
solution ask at <comp.text.xml>, for jQuery plugin ask at some Eclipse
forum.

*OR* Before you run your mouth off about something you have no clue
about - being in this case that the mentioned JQuery is a JAVASCRIPT
LIBRARY supporting css / xpath / expressions to apply behaviors to dom
elements.

To the original poster. Drop John Resig an Email from the form on the
jquery page. I have had similiar issues with the xpath selectors. Some
of the custom expressions might be useful to you though.
 
V

VK

*OR* Before you run your mouth off about something you have no clue
about - being in this case that the mentioned JQuery is a JAVASCRIPT
LIBRARY supporting css / xpath / expressions to apply behaviors to dom
elements.

Or really? Which one of them? There are at least 3 plugin/library
called jQuery (variant JQuery) matching the OP's description. The name
is too "sound" for a bizword so all kind of wannabes used it for
software of all kinds of quality. Presuming for a minite it is not
about Eclipse but about <http://jquery.com/> (just one of numerous
variants). In such case I'm sure OP will be glafle helped at
<http://jquery.com/discuss/>

If OP wanted a JavaScript help, then the traversal should go in the
normal way, not upside down as (I presume) suggested by the "logic" of
the library. Namely on a standard-compliant page (thus all labels have
"for" attribute) one retrieves all labels for a given range and /then/
accesses the attached elements:

var labels = document.getElementsByTagName('LABEL');
var obj = null;
for (var i=0; i<labels.length; i++) {
obj = document.getElementById(labels.htmlFor);
if (obj.checked) {
labels.style.backgroundColor = 'red';
}
}

This is about JavaScript; for jQuery/JQuery/jquery use relevant URL's.
 
G

Gale

VK said:
*OR* Before you run your mouth off about something you have no clue
about - being in this case that the mentioned JQuery is a JAVASCRIPT
LIBRARY supporting css / xpath / expressions to apply behaviors to dom
elements.

Or really? Which one of them? There are at least 3 plugin/library
called jQuery (variant JQuery) matching the OP's description. The name
is too "sound" for a bizword so all kind of wannabes used it for
software of all kinds of quality. Presuming for a minite it is not
about Eclipse but about <http://jquery.com/> (just one of numerous
variants). In such case I'm sure OP will be glafle helped at
<http://jquery.com/discuss/>

If OP wanted a JavaScript help, then the traversal should go in the
normal way, not upside down as (I presume) suggested by the "logic" of
the library. Namely on a standard-compliant page (thus all labels have
"for" attribute) one retrieves all labels for a given range and /then/
accesses the attached elements:

var labels = document.getElementsByTagName('LABEL');
var obj = null;
for (var i=0; i<labels.length; i++) {
obj = document.getElementById(labels.htmlFor);
if (obj.checked) {
labels.style.backgroundColor = 'red';
}
}

This is about JavaScript; for jQuery/JQuery/jquery use relevant URL's.


I want to do it with XPath !!!
 
G

Gale

VK wrote:

To the original poster. Drop John Resig an Email from the form on the
jquery page. I have had similiar issues with the xpath selectors. Some
of the custom expressions might be useful to you though.

Thank you I will try that!
 
V

VK

Gale said:
I want to do it with XPath !!!

You cannot do it with XPath: XPath is a language to traverse nodes in
XML document during the transformation (look for XSLT). On the
mentioned stage JavaScript is useless as the resulting document doesn't
exist yet. Never repeat someone bogus ads just because it sounds cool.
You mean to say "I want to do it using pseudo-XPath syntax supported in
the used JavaScript library". As internally these "XPath commands" is
nothing but plain strings parsed and used by JavaScript functions, I
presume some string parsing bug. Follow the advise of other poster -
simply be aware that you are not using XPath - you are using XPath-like
syntax. That makes a difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top