Get input value using data attribute with jquery
How can I get the input value using data attributes using jQuery? This is my function not working. the return value of valuefromscenariotwo should be "My test 2"
var valuefromscenariotwo = getvaluefromScenariotwo("scenario2");
function getvaluefromScenariotwo(name){
return $(input[data-scenario=name]).val();
}
<div class="form-group">
<input type="text" data-scenario="scenario1" class="form-control notes" placeholder="Enter Notes" value="My test 1">
</div>;
<div class="form-group">
<input type="text" data-scenario="scenario2" class="form-control notes" placeholder="Enter Notes" value="My test 2">
</div>;
<div class="form-group">
<input type="text" data-scenario="scenario3" class="form-control notes" placeholder="Enter Notes" value="My test 3">
</div>;
+3
source to share