4

I've inherited some javascript, and it's not all working as expected at the moment. This is one sticking point:

jQuery("#theForm")
  .find("input[@checked], input[@type='text'], options[@selected], textarea")
  .each(function() { ... });

I'm not familiar with the [@] syntax (though it seems clear what it wants to have happen), and I'm not finding documentation. Can anyone tell me if this is valid jquery?

1
  • I'm just curious, are you serializing a form for AJAX submission here? That's what it looks like, and there are built-in methods if that's the case :) Aug 27, 2010 at 14:11

4 Answers 4

5

The @ is an xpath selector (has attribute), which has been deprecated since jQuery 1.1.4. Just leave it out, or replace those with pseudo-selectors:

jQuery("#theForm")
.find("input:checked, input:text, option:selected, textarea")
.each(function() { ... });

See http://api.jquery.com/category/selectors/

1

The @ in selector isn't valid now, you need to leave that out:

input[type='text']

So you should remove all instances of @ from your code.

jQuery('input:checked') // gets all checked input fields
jQuery("input[type='text']")   // gets all text input fields
jQuery("select option:selected").text()  // gets text of selected option in dropdown
1

"[...]" basically means "which has".

"@name" means attribute "name"

So "Input[@type='text']" means an text input element (<input type='text'>)

'@' is the correct syntax for XPath, however, it's not used by CSS, and jQuery has now switched to the CSS format, so it should be removed.

0

Here's how to do it :

  • For checked selector : input:checked.
  • For input text : input[type=text]
  • For selected : option:selected

'@' will only work with some old jquery libraries because it's now deprecated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.