Bonjour,
Je suis sur un devoir en jQuery, je trouve pas pourquoi le if est pas accessible, j'ai essayé ("ok", 'ok', ok), de manière a re faire disparaître la div
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
}
#gauche {
float: left;
width: 70%;
height: 1000px;
background-color: #EFECCA;
}
#droite {
background-color: #CEFFF8;
height: 1000px;
padding : 10px;
padding-left: 71%;
}
#insertion {
margin-top: 20px;
}
</style>
</head>
<body>
<div id="gauche">
</div>
<div id="droite">
Utilisez ces boutons pour créer votre formulaire<br><br>
<button>Label</button>
<button>Zone de texte</button>
<button>Bouton</button>
</div>
<script src="https://code.jquery.com/jquery-3.0.0-alpha1.js"></script>
<script>
$(function() {
$('<div id="insertion"></div>').appendTo($('#droite'));
$('<label for=""></label>').appendTo($('#insertion'));
$('<input type="text" id="text"></input>').insertAfter($('label'));
$('<button id="envoi">ok</button>').insertAfter($('input'));
$('#insertion').hide();
var selectbutton = ($('button'));
selectbutton.click(function() {
console.log(this.firstChild);
if (this.firstChild === "ok") {
var submit = $('#insertion');
submit.hide();
console.log("tous est ok");
}
else {
$('#insertion').show();
var alemacti = this.firstChild;
$('label').replaceWith('<label>' + alemacti.nodeValue + '</label>');
console.log(alemacti.nodeValue);
var testif = $('button');
}
});
});
</script>
</body>
</html>
Merci par avance de vos réponse.