0

when i write like this

function go(){
    alert("ok");
    $('#content').css("color","red");
    alert("good");
}

it prints "ok" but do not change css and does not print "good". This is my Jquery file.

<div id = "content">
    <a class="left-side1" href="http://localhost/codeigniter/index.php/project/main" onClick="go();">Some Text</a>
</div>

and there i'm calling function go()

May you help me please

4

3 回答 3

1

You are changing the container not the link color. Change your code to the following. It prints "ok" and crashes after because you do not have the jquery library included. Include the library by the following, and then change your javascript as given below.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<script>
function go(){
    alert("ok");
    $('#content a').css("color","red");
    alert("good");
    return false;
}
</script>
于 2013-06-18T20:55:06.010 回答
0

Code looks ok.

Perhaps you need to include the jQuery library before your script?

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
于 2013-06-18T20:54:53.027 回答
0

You should use the jQuery click event like below.

$("#content a").click(function(event) {

  event.preventDefault();
  $("#content a").css("color","red");

});

The preventDefault(); is there to cancel the default link action.

Preventing the default action will mean that the link dosen't work anymore, if you want to change the link colour after its been clicked and the page is re-loaded then you will need to use a different method.

于 2013-06-18T21:00:08.117 回答