Solved

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

Posted on 2016-11-30
2
67 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

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 57

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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
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…

696 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