Javascript nodevalue

605 views Asked by At

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?

3

There are 3 answers

0
Ilya Trofimof On BEST ANSWER

What is "rutabaga" and "likerutabagas" ... ?

If id try: var myRutabaga = $("#rutabaga");

If class : var myRutabaga = $(".rutabaga");

5
FarligOpptreden On

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");
}
0
Tasnim Reza On

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 !