March 24, 2012
Hide the span with a class name jquery
Question by Sethen Maleno
I am stuck on what to do when hiding a span that has a certain class name. I can’t use this
because it refers to the input. Here is my script:
//uncheck all checkboxes
$("input[type=checkbox]").prop("checked", false);
$("input[type=checkbox]").each( function (index) {
$(this).addClass("doc" + index);
})
$("input").change( function () {
var docName = $(this).parent().find("span");
var className = $(this).attr("class");
if(this.checked) {
$("span.noneAttached").fadeOut('slow', function () {
docName.clone().appendTo(".attachedDocuments").addClass(className).after("<br />").text();
});
}
else if (!this.checked && ($(".attachedDocuments > span").hasClass(className))) {
//hide the span with the class name
}
});
The else if
checks to see if a checkbox is not checked and if the parent div contains any children with the class name. If so, hide it.
Where do I go from here? I am sure this answer is obvious, but I am just not seeing it.