javascript - Jquery empty() or remove() wont work -
i working on little game practicing jquery , php. clicking on right spot you'll go next question or have fail. checking right answer use img(img of question) usemap
<img id="questions" src="../img/items/question1.png" style="height: 450px;width: 700px;" usemap="#result"> <map name="result"> </map>
as can see, map has no area's. add in script:
$(document).ready(function(){ var score = 0; var answer1 = '<area class="true" shape="circle" coords="145, 175, 40" href="#">'; var entireimg = '<area class="false" shape="rect" coords="0, 0, 700, 450" href="#">'; $(answer1).appendto('map'); $(entireimg).appendto('map'); $('.true').click(function(){ score++; $('#questions').attr({src: "../img/items/question2.png"}); }); $('.false').click(function(){ $('#questions').attr({src: "../img/items/fail.png"}); $('.notes').show(); }); });
if got right answer add new area right answer location each question. problem got is; cant remove previous answer area form. what tried far:
changing variable other location add to map:
$('.true').click(function(){ score++; $('#questions').attr({src: "../img/items/question2.png"}); answer1 = '<area class="true" shape="circle" coords="200, 300, 40" href="#">'; $(answer1).appendto('map'); });
remove var map:
$('.true').click(function(){ score++; $('#questions').attr({src: "../img/items/question2.png"}); $('answer1').remove(); });
remove added element:
$('.true').click(function(){ score++; $('<area class="true" shape="circle" coords="145, 175, 40" href="#">').remove(); });
and empty value (and empty value , append 'empty' value again).
non of work, , knowledge have far (witch not much) cant figure out (already spent 2 hours googling around).
i put game online on links: http://i333180.iris.fhict.nl/demo/pages/index.php
regards
since want remove element you're clicking on, use:
$(".true").click(function() { score++; $(this).remove(); });
Comments
Post a Comment