Savoir si un id en presente dans un div
bonjour,
je cherche recupéré un id sous la condition qu' un checkbox sois coché et le la div avec id="valide" sois present.
voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| $(function() {
var monTableau = []
var id = []
$(':checkbox[id^="check_"]').change(function(){
if ($('div[id^="valide"]').empty()){
if ($(this).prop('checked')==true) {
id = $(this).val()
monTableau.push(id)
$('#valueid').val(monTableau)
console.log( monTableau)
}
else {
id = $(this).val()
monTableau.splice( $.inArray(id,monTableau) ,1 );
$('#valueid').val(monTableau)
}
}
});
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
if ($(this).prop('checked')==true) {
$(':checkbox[id^="check_"]:checked').each(function () {
id = $(this).val()
monTableau.push(id)
$(this).val(monTableau)
$('#valueid').each(function () {
$(this).val(monTableau)
console.log(monTableau)
})
});
}
if ($(this).prop('checked')==false) {
monTableau= [];
$('#valueid').val(monTableau)
}
});
}); |
c'est la condition de la div qui me pose problème.
merci de votre aide