What am trying to do is something like this
$('input[type="text"],input[type="checkbox"],textarea').not(data-value="SHControl").attr('readonly','readonly');
Please provide me the correct syntax to achieve the same.
What am trying to do is something like this
$('input[type="text"],input[type="checkbox"],textarea').not(data-value="SHControl").attr('readonly','readonly');
Please provide me the correct syntax to achieve the same.
I think what you're looking for is the syntax for using .not
in jQuery. What you want to do is this:
$('input[type="text"],input[type="checkbox"],textarea').not('[data-value=SHControl]').attr('disabled', 'disabled');
Created a jsfiddle here to show how it works: https://jsfiddle.net/clausjensen/e24seukm/
$('input[type="text"],input[type="checkbox"],textarea').each(function() {
var el = $(this);
el.prop("readonly", el.data("value") !== "SHControl");
})
*[readonly] {
border: solid 1px red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" />
<input type="text" data-value="SHControl" />
<textarea></textarea>
A checkbox has no readonly
state as this only prevents the manipulation of the value
attribute ->
Can HTML checkboxes be set to readonly?
hello this the solution of added readonly
<style>
*[readonly] {
border: solid 1px red
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="application/javascript">
$(document).ready(function(e) {
$('.test').each(function(index, element) {
if($(this).attr('data-value')!="SHControl"){
$(this).attr('readonly','readonly');
}
});
});
</script>
<input class="test" type="text" data-value="SHControl"/>
<input class="test" type="checkbox" data-value="SHControl"/>
<textarea class="test" data-value="SHControl" ></textarea>
<input class="test" type="text" data-value="SHControl1"/>
<input class="test" type="checkbox" data-value="SHControl1"/>
<textarea class="test" data-value="SHControl1" ></textarea>
Correct syntax is:
$("input[type='text'], input[type='checkbox'], textarea").not("input[data-value='SHControl']").attr("readonly", "readonly");