i have no idea what i'm doing wrong. It's simple code, but doesn't work.
<div id="demo1" class="rating">
<input class="stars" type="radio" id="1" name="rating" value="1" />
<label class = "full" for="star5" title="Awesome - 5 stars"></label>
</div>
<div id="demo2" class="rating2">
<input class="stars" type="radio" id="2" name="rating" value="1" />
<label class = "full" for="star5" title="Awesome - 5 stars"></label>
</div>
$(document).ready(function () {
$("#demo2 input.stars").click(function () {
alert('2');
});
$("#demo1 input.stars").click(function () {
alert('1');
});
});
This code works fine (when i click first radio, it's alert "1", when click second it's alert "2").
But... with this CSS:
<style>
/****** Rating Starts *****/
@import url(http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
fieldset, label, span { margin: 0; padding: 0; }
body{ margin: 20px; }
h1 { font-size: 1.5em; margin: 10px; }
.rating {
border: none;
float: left;
}
.rating > input { display: none; }
.rating > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating2 {
border: none;
float: left;
}
.rating > label {
color: #ddd;
float: right;
cursor:pointer;
}
.rating2 > label {
color: #ddd;
float: right;
cursor:pointer;
}
.rating2 > input { display: none; }
.rating2 > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f164";
}
</style>
...with this css, i always get alert 1.
Help, please. No idea why when i click second radio i have alert 1 instead 2.
Regards Luke
.rating > input { display: none; }and.rating2 > input { display: none; }will do it. Your rating inputs (which the click event is tied to) is not visible any more. Therefore, there's nothing on the page which will respond to your event.