0

Anyone can please tell me How can I get an internal stylesheet using jQuery. I know how to get the style of hello class but I want to take the style of world class.

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		.hello{
			color: red;
		}
		.world{
			color: blue;
		}
	</style>
</head>
<body>
    <p class="hello">Hello world!</p>
</body>
</html>

2

2 Answers 2

0
<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        .hello{
            color: red;
        }
        .world{
            color: blue;
        }
    </style>
</head>
<body>
    <p class="hello">Hello</p> 
    <p class="world">world!</p>
</body>
</html>
0

You define as .hello class but .world class is not declare how could it response both color in a one class attribute

Based on Jquery You refer this one

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<title>Page Title</title>

</head>
<body>

 <p class="hello">Hello world!</p>
 </body>
</html>

<script>
 $(document).ready(function(){ 

    var n = $(".hello").length;

    if (n < 2) {
        $(".hello").css("color", "red");
       $(".hello").css("background", "blue");

    } 
    else {
        $("body").css("color", "orange");
    }

});

</script> 

Check Below Link here

1
  • Above link for practice u paste my code and check once... Jul 24, 2018 at 5:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.