-2

i got a question (i guess it is really simple but i really can't find it cause it's really specific).

I'd like to find how to use selector on a Jquery Object representing a DOM element.

Here is an exemple of what i want to do.

HTML:

<div id="template">
    <button class="buttonRemove"></button>
    ...A Lot of other HTML Content...
</div>

JQuery:

var myTemplate = $("#template").clone(true);
myTemplate.attr("id","a_new_customized_id");
myTemplate.A_WAY_TO_SELECT_BUTTON_WITH_CLASS_REMOVE.hide();

I'd like to do that cause of two reason : I'm using my real template for some differents functions (Like Showing informations that can be delete, and some others that can't)

Thx !

EDIT: Thx everyone for your responses. I tried a lot of thing like "$.myTemplate.("selector")" before you gave me the solution.

I just found an other solution that is :

$('#buttonRemove',myTemplate)

If you use a 2nd parameter in the selector method, it will be use as the domain of research for the selector. (Default : document)

4

3 回答 3

4
myTemplate.A_WAY_TO_SELECT_BUTTON_WITH_CLASS_REMOVE.hide()

is written like this, ( let's say your class is "remove")

myTemplate.find('button.remove').hide()
于 2013-07-01T14:09:33.733 回答
3
myTemplate.find('button.buttonRemove').hide();

This will have no effect if the cloned element is not appended to the DOM later/earlier.

于 2013-07-01T14:09:36.150 回答
1
myTemplate.find('button.remove').hide();

This find in myTemplate for button with remove class.

于 2013-07-01T14:10:10.393 回答