Jump to content

Recommended Posts

Is there a way with javascript to change a css class?

 

If I have a class

 

#content p.checkbox {

  padding: 4px 1px 0 0;

  height: 31px;

  background-color: #fff;

}

 

and want to change the background color to #ff0000 on a mouseover is there javascript to allow that?

 

Link to comment
https://forums.phpfreaks.com/topic/198278-javascript-to-change-a-css-class/
Share on other sites

Here is the jQuery version of that. Just include the jQuery library in the head

 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

 

Then add this.

 

<script  type="text/javascript">
$(document).ready(function(){
  $('#content p.checkbox').hover(function(){
    $(this).css('bacground', '#ff0000');
  }, function(){
    $(this).css('bacground', '#ffffff');
  });
});
</script>

 

A bit extensive to include a library for one functionality.

 

Anyway, not sure if this works:

 

#content p.checkbox:hover { 
  background-color: #ff0000 !important;
}

 

I don't even understand the concept of this. You want to change the checkbox background color?

A bit extensive to include a library for one functionality.

 

Anyway, not sure if this works:

 

#content p.checkbox:hover { 
  background-color: #ff0000 !important;
}

 

I don't even understand the concept of this. You want to change the checkbox background color?

 

That will work but not for IE

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.