Sethen
Sethen

Reputation: 11348

Hide the span with a class name jquery

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.

Upvotes: 2

Views: 10715

Answers (3)

naim shaikh
naim shaikh

Reputation: 1111

Try this

$(".attachedDocuments span." + classname).hide();

Upvotes: 1

Kyle Macey
Kyle Macey

Reputation: 8154

$('.classname').hide();
$('.' + classnameasvariable).hide()

Upvotes: 0

Starx
Starx

Reputation: 78971

Concatenate the class name to the selector like this

$("span."+className).hide();

Upvotes: 5

Related Questions