4
I have a certain div.box
that will be repeated several times, and some of them have a link (a.link
) with a specific class.
Example:
<div class="box" data-id="1">
Primeiro texto
</div>
<div class="box" data-id="2">
Segundo texto <a class="link">Clique aqui</a>
</div>
<div class="box" data-id="3">
<a class="link">Clique aqui</a>
</div>
<div class="box" data-id="4">
Testando
</div>
Das divs
above, I need to detect that, around the a.link
, no text exists. That is, from the above example could return only to div.box
whose the data-id
is equal to 3
.
How can I detect it through jQuery?
I mean, I have to make sure that the div.box
contains only that element within it a.link
(and nothing more).
+1. The idea of the function is wonderful. This makes the code reusable.
– Wallace Maxters
@Wallacemaxters great! Next time you can leave the question open longer :P
– Sergio
Yeah, @bigown had been talking for a long time for me to stop this craze. Sometimes I think there won’t be many who will answer
– Wallace Maxters
@Wallacemaxters I sometimes see the question at work and only when I get home do I have time to answer... you have nothing to lose :)
– Sergio
@Wallacemaxters nothing prevents you from exchanging acceptance. Accept the one that is best.
– Maniero
If you give a improved in code, you a little performance.
– DontVoteMeDown
@Dontvotemedown is true that sometimes I do more complete for the user to understand the steps. I could optimise more but I don’t think it’s safe to say that one is faster than the other: http://jsfiddle.net/kps5xbec/5/
– Sergio
Yes, your answers are great. In this case what differed from mine was having created a function and I did not, but it was the same, I think. The two codes get really close(1 and 2, I don’t usually use Date for these tests), but I can’t deny that
$(el).parent().find(seletor)
can be executed outside the secondfilter()
, for within it is reductive.– DontVoteMeDown
@Dontvotemedown you’re right that this
.find()
may be out of thefilter()
. Good point. I joined in response a new version.– Sergio