I am a beginner in jQuery programming. I am trying to fire a click event on list click, but it is not working properly. The following is my code:
<html>
<head>
<script type="text/javascript" >
<script type="text/javascript" src="jquery.js">
<link rel="stylesheet" href="style.css" />
$("ul#select li").click(function(e){
//targ = $(e.target);
if($(this).hasClass("selected"))
{
$(this).removeClass("selected");
document.location= "cambridge:clearanswer";
}
else
{
currentanswer = $(this).html();
document.location = "cambridge:checkanswer:"+currentanswer;
$("ul.select li").removeClass("selected");
$(this).addClass("selected");
}
});
function getUsed()
{
var total = "";
$(".boxWord.boxWordUsed").each(function (i){ total = total + this.getAttribute('index_no') + ":"; });
return total;
}
</script>
</script>
<link href="style.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="question" >
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b" class="select" id="select">
<li data-role="list-divider" class="selected">Overview</li>
<li data-role="list-divider" class="selected">Overview</li>
</ul>
</div>
</body>
</html>
First of all you are not writing codes in
<script>tag and the code messed up between multiple tags. Then you have use$(document).ready(). You also have other errors in code, I have corrected all of them for you, I understand you are a newbie :).See a working demo here http://jsfiddle.net/DtHJY/1/
Here is the corrected code: