0

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.

4 Answers 4

1

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/

Sign up to request clarification or add additional context in comments.

Comments

0

$('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?

Comments

0

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>

Comments

0

Correct syntax is:

$("input[type='text'], input[type='checkbox'], textarea").not("input[data-value='SHControl']").attr("readonly", "readonly");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.