I have the following example:
Is there a way to check if this element exists and ha
You can create your own custom selector :hasValue
and then use that to find, filter, or test any other jQuery elements.
jQuery.expr[':'].hasValue = function(el,index,match) {
return el.value != "";
};
Then you can find elements like this:
var data = $("form input:hasValue").serialize();
Or test the current element with .is()
var elHasValue = $("#name").is(":hasValue");
jQuery.expr[':'].hasValue = function(el) {
return el.value != "";
};
var data = $("form input:hasValue").serialize();
console.log(data)
var elHasValue = $("[name='LastName']").is(":hasValue");
console.log(elHasValue)
label { display: block; margin-top:10px; }
Further Reading: