tags:

views:

26

answers:

2

Hi all..

Time for another silly question :)

I got some tables in a xhtml-document with class="mytable" and inside those tables all sorts of elements, including <input type="checkbox"/> .. Now, I need to select all these checkboxes. I figured I'd use jquery with xpath, but my expression doesnt seem to work.

So far, I've come up with

$("table[class=mytable]//input[type=checkbox]")

.. but that doesnt seem to work :( Any help is appreciated :)

A: 
$("table[@class='mytable']//input[@type='checkbox']")

I think you need the @ symbol to target attributes and single quotes around the attribute values

Nick Allen - Tungle139
Sadly that's not it :) As of jQuery 1.3+ you cannot use the @ in attribute selections. At least that what it states here: http://dev-tips.com/featured/jquery-tip-using-xpath-selectors . "As of jQuery 1.3, the attribute selector '@' has been deprectaed and will break in the latest version of jQuery. This is an easy fix, simply remove the @ selector". Besides, I can do selections just fine without the //. Thanks for trying though :)
cwap
Oh wow. How the heck can JQuery remove support for a basic XPath feature like that? Using "@" to distinguish attribute children from element children has been a core feature of XPath queries for years before JQuery ever existed. If they JQuery is saying that they no longer support the "@", it's like saying that you no longer support XPath, which seems bizarre
Mike Mooney
+2  A: 

I would use Css selectors not xpath

$('table.mytable input[type="checkbox"]')
David Waters
Yeah, guess that's easier :) Just wanted to try and fiddle with xpath, but I'll use css selectores instead. Thanks :)
cwap
@cwap: You can't use real XPath in a jQuery selector anyway.
Tomalak
@cwap no worries, sorry for not answering the question on xpath.
David Waters