Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery is not generating any Output

I am new to jQuery. I am trying to create this simple effect but its not generating any output. Please tell me why its not working.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


<link rel="stylesheet" href="style.css" >
</head>



    <body>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
    <script type="text/javascript"  src="table.js" ></script>




    <div class="table">
    <p>MyPara</p>
    <p>MyPara2</p>
    <p>MyPara3</p>
    </div>

    </body>

table.js

// JavaScript Document

$(document).ready(function() {

    $('table').addClass('highlight');
});

Stylesheet

.highlight
{
    background-color:#999;


    }
like image 664
Aftab Aamir Avatar asked Feb 26 '26 21:02

Aftab Aamir


2 Answers

You have to use . before class name. Here you are missing it. Your code should be like this.

$(document).ready(function() {

    $('.table').addClass('highlight');
});
like image 86
Taha Kirmani Avatar answered Mar 01 '26 09:03

Taha Kirmani


you need to use . for class, change:

$('table').addClass('highlight');

to

$('.table').addClass('highlight');
like image 32
Sudhir Bastakoti Avatar answered Mar 01 '26 11:03

Sudhir Bastakoti