function count() {
$("input:radio")[1].html = alert("We're from the same site");
$("input:radio")[0][2][3].html = alert("We are not from the same site");
}
<html>
<head>
<title>jQuery Script</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript" language="javascript">
</script>
</head>
<body>
<h1>Select one campus</h1>
<form>
<input id="Belfast" type="radio"> Belfast
<input id="Jordanstown" type="radio"> Jordanstown
<input id="Magee" type="radio"> Magee
<input id="Coleraine" type="radio"> Coleraine
<br> <br>
<input type = "button" value="Count" onclick="count()">
</form>
<input type="button" value="Reload page" onclick="reloadPage()">
</body>
</html>
Can anybody help me out with this piece of code? I'm learning jQuery at the moment and I am trying to create a jQuery script to check if a visitor is on the same university campus as me. I am using the following code:
When I select the second option on screen it works as expected but for any other, it seems to be giving me the exact same alert box like this:
Selecting the correct campus site
Selecting any other listed campus site.
I think the error lies somewhere within my count() function but I cannot see what the problem is:
function count() {
$("input:radio")[1].html = alert("We're from the same site");
$("input:radio")[0][2][3].html = alert("We are not from the same site");
}
alertcalls (which is not useful --alertalways returnsundefined!) in a property of some DOM element namedhtml, which is not a property that affects the DOM of the page (unlike, e.g.,innerHTML).$("input:radio")[0][2][3]? You're not taking advantage of jQuery.