JavaScript JavaScript Validation Error in my excercise javascript validation error message display,javascript validation error,javascript validation

Your needed variable is causing the problem.

http://jsfiddle.net/6gkpyhyf/

 needed = $(this).text();

Change from needed = $(this).html(); to needed = $(this).text();

Answer:1

The problem is that on each click on li you append image again and again, event it's already been checked before. So you need a way to know that this element is already clicked and do nothing in this case.

For example you can add additional CSS class. Something like this (with some additional improvements to the code):

$('ul.gift li').click(function (e) {

    if ($(this).hasClass('answered')) {
        return;
    }

    var correct = "gift";
    var needed = $(this).html();

    if (correct == needed) {
        var $innercontent = '<img src="images/right.png">';
        $(this).addClass('answered correct').append($innercontent);
    } else {
        var $innercontent = '<img src="images/wrong.png"></li>';
        $(this).addClass('answered wrong').append($innercontent);
    }
});

Demo: http://jsfiddle.net/LvrLtchf/

A few notes. 1). Instead of $( e.target ).closest("li") you can simply use $(this) as in your case this is the same element. 2). Always declare variables with var keyword. 3). Instead of inline styles it's more flexible to use classes, e.g. .right {color: green} instead of style="color: green".

Answer:2

		$(document).ready(function() 
         {
            $('ul.gift li').click(function(e) 
            { 
                correct = "gift";
                needed = $(this).html();

                if(correct==needed){
					$(this).addClass('correct');
				}else{
					$(this).addClass('incorrect');
				}
});
});
ul li {
			background-position: right center;
			background-repeat: no-repeat;
			background-size: 30px 30px;
			height: 30px;
			width: 100px;
		}
		.correct {
			background-image: url(http://chinagorman.files.wordpress.com/2011/10/check-mark-small.jpg);
			color: green;
		}
		.incorrect {
			background-image: url(https://www.catholicmatri.com/images/wrong-icon.png);
			color: red;
		}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="list gift">
            <li>gasp</li>
            <li>gift</li>
            <li>golf</li>
            <li>gust</li>
        </ul>
Answer:3

Just via CSS with less JavaScript is a bit cleaner

$(document).ready(function () {

    $('ul.gift li').click(function () {

        var correct = "gift",
            given = $(this).text();

        $("ul.gift li").removeClass("co in");
        if (correct === given) {
            $(this).addClass("co");
        } else {
            $(this).addClass("in");
        }

    });
});

.co:after{
 content:url("http://findicons.com/files/icons/1609/ose_png/256/tick.png");
 zoom: .06;

}
.in:after{
  content:url("http://findicons.com/files/icons/1014/ivista/128/error.png");
  zoom: .1;
}
li:hover{
  cursor:pointer;
}

http://jsbin.com/retujikoto/1/edit

Answer:4

I'm using Cors requests to communicate between my client and server placed in two different domain. I configurate my apache http server this way it's using SSL : //with AJAX withCredentials=true (...

I'm using Cors requests to communicate between my client and server placed in two different domain. I configurate my apache http server this way it's using SSL : //with AJAX withCredentials=true (...

  1. cors request method options
  2. cors access-control-request-method
  3. invalid cors request post method

Im using dropzonejs to upload photos to my website. The problem is, when I click dropzone to upload, it won't show 'Gallery' as an option as seen in this image : How to add Gallery as an option?

Im using dropzonejs to upload photos to my website. The problem is, when I click dropzone to upload, it won't show 'Gallery' as an option as seen in this image : How to add Gallery as an option?

  1. upload photo from iphone
  2. upload photo from iphone to pc
  3. upload photo from iphone to icloud
  4. upload photo from phone to pc
  5. upload photo from desktop to instagram
  6. upload photo from computer to iphone
  7. upload photo from pc to instagram
  8. upload photo from iphone to google drive
  9. upload photo from iphone to dropbox
  10. upload photo from pc to icloud
  11. upload photo from computer to instagram
  12. upload photo from iphone to facebook
  13. upload photo from mac to iphone
  14. upload photo from camera roll to snapchat
  15. upload photo from instagram web
  16. upload photo from gallery android studio
  17. upload photo from iphone to laptop
  18. upload photo from mac to instagram
  19. upload photo from phone to laptop
  20. upload photo from mac

I am trying to implement a chat application using the codeigniter framework but on form submit, the form data does not get submitted and the submit button becomes disabled. when I check on the ...

I am trying to implement a chat application using the codeigniter framework but on form submit, the form data does not get submitted and the submit button becomes disabled. when I check on the ...

  1. codeigniter chat application github
  2. codeigniter chat application source code
  3. codeigniter chat application
  4. codeigniter chat application example
  5. codeigniter chat app
  6. php codeigniter chat application
  7. codeigniter realtime chat application with jquery and ajax

Sincere apologies if this has already been covered. I've been trawling StackOverflow for a while now and I cannot find anything that will fix my issue. Many people have this error, but theirs seem to ...

Sincere apologies if this has already been covered. I've been trawling StackOverflow for a while now and I cannot find anything that will fix my issue. Many people have this error, but theirs seem to ...

  1. uncaught referenceerror functionname is not defined