Reputation: 93
What is wrong with this code?
var myRutabaga = $("rutabaga");
if(myRutabaga.checked){
document.$("likerutabagas") = "LIKE";
}else{
document.$("likerutabagas") = "DO NOT LIKE";
}
It will not execute. I need to find the nodevalue too. How can I fix it?
Upvotes: 1
Views: 605
Reputation: 5043
If "rutabaga" is the id of an element, you need to use the $("#rutabaga") selector.
If "rutabaga" is a class of an element, you need to use the $(".rutabaga") selector.
Just using the $("rutabaga") selector means that jQuery is looking for a tag name of "rutabaga", which shouldn't exist. :)
You can also use the jQuery .is(":checked") function to test whether the input is checked or not, like so:
if ($("#rutabaga").is(":checked")) {
$("#likerutabagas").text("Like");
}
else {
$("#likerutabagas").text("Do Not Like");
}
Upvotes: 1
Reputation: 6060
please make sure proper selection of html DOM. you should use # for ID or . for class or others valid selector.
var myRutabaga = $("#rutabaga")// or use $(".rutabaga");
if(myRutabaga.checked){
$("#likerutabagas").text("LIKE"); // or use .html("LIKe")
}else{
$("#likerutabagas").text("DO NOT LIKE"); // or use .html("DO NOT LIKE")
}
now may it works !
Upvotes: 1
Reputation: 26
What is "rutabaga" and "likerutabagas" ... ?
If id try: var myRutabaga = $("#rutabaga");
If class : var myRutabaga = $(".rutabaga");
Upvotes: 1