0

This seems not to be the right way:

$(".row-fluid div").each(function() {
    var $this = $(this),
        getClassLFT = $this.attr("class").split(" ").map(function(item) {
            return item.indexOf("lineFromTop") === -1 ? "" : item;
        });

    // following line throws the error
    $this.find("."+ getClassLFT[0]).wrapAll("<div class='clear' />");
});

The last line throws following error: Syntax error, unrecognized expression: . I want to get the first (and it's the only) value in this object. How can I handle that?

4

2 回答 2

2

Everything is fine in your codepiece. But the collection getClassLFT may be empty and you may need to check it before using ...

if(getClassLFT.length){
  $this.find("."+ getClassLFT[0]).wrapAll("<div class='clear' />");
}
else{
  // handle here...
}

or use jQuery.isEmptyObject()

于 2013-01-10T14:09:36.893 回答
1

I think there poblem with the getClassLFT[0], it might be empty collection that why its giveing error..

you need to check you code to fill the collection of getClassLFT[0]

于 2013-01-10T13:56:49.783 回答