I’m completely new on JQuery and not so used to JavaScripting yet.
I have a form with named (attribute ‘name’) elements that I need to process one by one. I also want to update their class attribute if they are validated correctly.
I collected all the form elements with:
var Form = $('#'+fChildID).closest('form')[0];
var Element;
if (Form) {
for(var n=0; n<Form.length; n++) {
Element = Form.elements[n];
.
// Do some processing and validation
.
// Update the element's class attribute
$('*[name="'+Element.name+'"]').addClass("boxselected");
}
}
What I want to do is to use the function .addClass on the Element object, but it seems like JQuery always needs a selector and can’t operate directly on an object.
It seems to be that it would be unnecessary to use the * selector when I already have the Element object in a variable.
Can I also use the selector to check if certain attributes (plural) in the same element has specific values?
You can just use the element as the argument to the $ function, no other selector needed if you already have the element.
If you want to check for attribute values you can use
filter.