最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide the span with a class name jquery - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question asked Mar 24, 2012 at 5:42 SethenSethen 11.4k6 gold badges38 silver badges66 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 5

Concatenate the class name to the selector like this

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

Try this

$(".attachedDocuments span." + classname).hide();
$('.classname').hide();
$('.' + classnameasvariable).hide()
发布评论

评论列表(0)

  1. 暂无评论