Reputation: 129
How can I change the position of these textboxes in the load of my view ?
I want to have these chexboxes under the correct radio button when I load my page.
I already have it when I click on a radio button, but not in the load.
Here is my code: http://jsfiddle.net/Y3qN5/1/
$(document).ready(function() {
$('input[type="radio"]').click(function() {
var home = $(this).closest('div');
var div = $('#parametersFinancial').detach().appendTo(home);
});
});
Upvotes: 0
Views: 135
Reputation: 93601
Something like this:
$(document).ready(function() {
var moveIt = function($element){
var home = $element.closest('div');
var div = $('#parametersFinancial').appendTo(home);
}
$('input[type="radio"]').click(function() {
moveIt($(this));
});
moveIt($("input[type=radio]:checked"));
});
basically extract the bit that does the work and call it on load as well as on the clicks.
Note: that you don't need detach
as the DOM elements will be moved by appendTo
Upvotes: 1
Reputation: 43507
Just call function when your elements is loaded: http://jsfiddle.net/Y3qN5/2/
$(document).ready(function() {
$('input[type="radio"]').click(function() {
doStuff($(this));
});
doStuff($('checked radio button'));
});
Upvotes: 1