Reputation: 110
I need to disable the elements of class "gcf_crud" that are into a variable.
My wrong code is:
var defText = ''+
' <div class="form-group col-md-12">'+
' <h4 id="minimum-setp">{{title}}</h4>'+
' <input type="text" class="form-control gcf_crud" id="txtUsuari" value="{{data}}"/>'+
' </div>';
var defTextDisabled = $(defText).find('.gcf_crud').prop('disabled', true);
With this code i'm obtaining only the input but I need all the original html.
How may I do it right?
Regards, Seak
Upvotes: 2
Views: 1031
Reputation: 25634
Your defTextDisabled
variable only returns the input because of .find('.gcf_crud')
.
But it seems that you need a reference (variable) to a jQuery object containing all the elements. In order to do that, break down your process in steps:
var defText = '<div class="form-group col-md-12">'
+ '<h4 id="minimum-setp">{{title}}</h4>'
+ '<input type="text" class="form-control gcf_crud" id="txtUsuari" value="{{data}}"/>'
+ '</div>',
$defText = $(defText); // Save the entire thing here
// Now, you can disable the input
$defText.find('.gcf_crud').prop('disabled', true);
// And use the whole content
$('body').append($defText);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
Upvotes: 2