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 function to function, but what if you want to pass it from a regular js function into the jquery .attr()
value?
That might sound strange as a statement, that's why I'll include an example.
$(function() {
function definingVars() {
var Value = "Sucess with the value";
var Id = successWithTheId;
var Class = sucessWithTheClass;
return [Value, Id, Class];
}
$("input").attr({
// var df = definingVars(); Incorrect syntax!!!
value: df.Value,
id: df.Id,
class: df.Class
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="noSucessWithTheId" class="noSucessWithTheClass" value="No sucess with the value">
But as you can see the line that should aloud the attr
jquery function to capture the values from definingVars()
is clearly commented as that is not the correct syntax.
But how can you still pass on those variables?
That is my question