Carlos Carlos - 7 months ago 28
Javascript Question

Function in external jquery file not working

I saw many js files which we include in our html page and it start working. I have made simple function to check how it works, I made external file and then included it in my web page but it is not working. my code is....

<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="face.js"></script>
</head>
<body>
<div class="cl">check code</div>
</body>


//jquery

function mtLoan(){

$('.cl').css('background-color','#ff0000')

}

Answer

You can try this

HTML

<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="face.js"></script>
</head>
<body>
<div class="cl">check code</div>
</body>

JS CODE

$(document).ready(function(){
    $('.cl').on('click', function(){
       mtLoan();
    });
    function mtLoan(){
       $('.cl').css('background-color','#ff0000')
    }
});

http://jsfiddle.net/hhBFZ/11/

Comments