Is there a way to conditionally set an attribute using jQuery? For example, I want to simplify this:
$(element).val('99');
if ([condition]) {
$(element).attr('myAttr', 1);
}
This works, but forces me break the chaining of method calls. Instead, I would prefer something like this:
$(element).val('99').attr('myAttr', 1, [condition]);
So that the attribute is only set if the condition is true. How would I do this?