Solved

How can I make a css class read only with jquery?

Posted on 2016-11-30
2
46 Views
Last Modified: 2016-11-30
I have a class on a table row like the below. Can someone tell me how to make it read only with jQuery, so everything in that class will be read-only/not interactive (I have some drop downs etc in the row)?

<table>
     <tr class="colorCars">.
......

Open in new window

0
Comment
Question by:earwig75
2 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 41907539
Add the class as you did, but don't place it in your css file and and you can use css http://api.jquery.com/css/.  

You can also use addClass https://api.jquery.com/addclass/.  

CSS
.colorCars{
  /* nothing */
}

.colorCars.active{
  color:red;
}

Open in new window


JS
$(".colorCars").on("click", function(){
       $(this).addClass( "colorCars active" )
});

Open in new window


Depending on what you want to do and why, there are going to be many options.
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41907720
This will make readonly all the controls in that row.
If you are only using input and textareas you can set the readonly property like this
$('.colorCars select, .colorCars input, .colorCars textarea').prop({readonly: true});

Open in new window

This won't work on radio, checkbox and select controls - you would need to disable those like this
$('.colorCars select, .colorCars input, .colorCars textarea').prop({disabled: true});

Open in new window


Here is a sample that demonstrates both

Use the Mode selector to toggle between readonly and disabled to see how different controls react
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question