For example, there is <p class="ape">Element 1</p>
I use jquery to cache it into a variable:
var $ape = $('.ape');
Then I added a new one<p class="ape">Element 2</p>
What method should $ape use to refresh itself at this time? How to enable it to select two apes at the same time?
I don’t want to have to $('.ape') every time I call it, I just want to call the cached variable $ape
学习ing2017-07-05 10:45:06
The only way is to assign the value to $ape
again every time an element is added
淡淡烟草味2017-07-05 10:45:06
It is recommended to use $('.ape')
directly. Don't write code exactly according to your own wishes, try to adapt your code to the grammatical features. The code written this way is more valuable.
PHP中文网2017-07-05 10:45:06
Either reassign the value, or when inserting a node, trigger an event and reassign the value. Anyway, it’s just reassignment