Is the following possible to do?
$("#textarea1").val = function() {
$.each(data, function(i, j) {
if ($.trim($("#text2").val()) == j.l) {
return j.v;
} else {}
});
};
Can we conditionally set the value of some input type or div?
I assume you have some valid desgin-pattern reason for not simply calling
$("#textarea1").val(j.v)inside youreachfunction, instead of setting it externally to the function as you do now. (Perhaps you have many function objects whose logic you wish to use conditionally to set a large collection of inputs?)That said, your code just needs a few changes:
valfunction correctly (it’s a setter, not a settable property).returnstatement is terminating the function passed toeach, not the outer function. You should have theeachfunction set a variable and then break by returning false.It should look something like:
valwill automatically execute the function and use the return value.