How To Pass Multiple Variables From Funtion To Jquery Attr
This question is related to How to pass multiple variables from function to function So in the link above you might have seen how you can pass a variable(or mutiple) from functio
Solution 1:
What you are trying to do is to pass multiple properties to .attr()
, for which we uses an object with key/value pair.
So what you can do is to return an object from definingVars
and pass the value returned by definingVars
as the argument to attr()
like
$(function() {
functiondefiningVars() {
varValue = "Sucess with the value";
varId = successWithTheId;
varClass = sucessWithTheClass;
return {
value: Value,
id: Id,
class: Class
};
}
$("input").attr(definingVars())
});
Solution 2:
If you wanna stick with the current structure of definingVars()
, then Just call directly the function if you wanted :
$("input").attr({
value: definingVars()[0],
id: definingVars()[1],
class: definingVars()[2]
})
Post a Comment for "How To Pass Multiple Variables From Funtion To Jquery Attr"