Reputation: 13
I am facing a problem with JQuery data fetching directly from the User. What i want is to get the value from one class and set in another class data-value. Below is my rough structure -
Upvotes: 0
Views: 888
Reputation: 356
I am just assuming your html structure is something like :
<div>
<input type="text" name="text1">
<button type="button">Click Me!</button>
</div>
<div>
<input type="text" name="text2">
<button type="button">Click Me!</button>
</div>
<div>
<input type="text" name="text3">
<button type="button">Click Me!</button>
</div>
What you need is an event handler for the textboxes.
e.g
$(document).ready(function(){
$('input').change(function(){
$(this).next().data('value',$(this).val());
});
});
Here is a fiddle
https://jsfiddle.net/25r7n54y/
Upvotes: 0
Reputation: 1233
Generally you should provide HTML structure and what event should be fired. But I'll give you some sample code if you have structure like you draw above :
$('.black-box').each(function(index, item){
var value = $(item).val(); //get value of black box
$(item).next().attr('value', value); // set value to red box button
})
Upvotes: 1