By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

jQuery and XPath

P: n/a
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?

Jun 1 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
VK

Gale wrote:
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.

Jun 2 '06 #2

P: n/a

VK wrote:
Gale wrote:
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.


*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.

Jun 2 '06 #3

P: n/a
VK
Ab*********@gmail.com wrote:
*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[i].htmlFor);
if (obj.checked) {
labels[i].style.backgroundColor = 'red';
}
}

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

Jun 3 '06 #4

P: n/a
VK wrote:
Ab*********@gmail.com wrote:
*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[i].htmlFor);
if (obj.checked) {
labels[i].style.backgroundColor = 'red';
}
}

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


I want to do it with XPath !!!
Jun 3 '06 #5

P: n/a
Ab*********@gmail.com wrote:
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!
Jun 3 '06 #6

P: n/a
VK
Gale wrote:
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.

Jun 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.