user3771102 user3771102 - 6 months ago 10
CSS Question

Getting the * selector in jquery

This may be a stupid question for you but I'm really curious what if getting the

*
in my css using jquery? Like for example:

css:

* {
background: #fff;
}


jquery:

$(document).ready(function(){
$("*").css("color","#999999");
});


I have tested it and it doesn't work in jsfiddle. xD In my project it kinda work. All of my elements have
style="..."
.

JSFIDDLE

Is there a work around there? Should I set another class for it? What is the best way to change that? Please don't tell me to change my css file for that. As much as possible I don't want to change the file that I didn't make in the first place. Any suggestions is much appreciated. Thank you very much!

Answer

It doesn't work in your fiddle because you haven't imported jQuery library, and you have set the font color instead of the background-color.

But it works fine.

All selector doc

Example

$(document).ready(function(){
$("*").css("background-color","blue");
});
*{
  background-color:red;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
</tr>
<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
</tr>
<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
</tr>
</table>