1

how can I prevent reappending element if element in element already exists with this code?

<div class='weekHourValue' data-nameDay='Tuesday' data-week='34' data-day='10' data-month='5' data-year='2015'><div class='singleYearEvent'></div></div> <div class='weekHourValue' data-nameDay='Tuesday' data-week='34' data-day='10' data-month='5' data-year='2016'></div> 

and now I want to somethink like this

$(".weekHourValue[data-month='5'][data-day='10'] {where not exist in element}").append("<div class='singleYearEvent'></div>");

Is there any jquery function like this? thank you!

1
  • It seems like you should be able to use a jQuery selector to get all weekHourValue elements with the correct day and month, then check through each of them to see if any one of them has the appropriate child element via a filter function. Commented Sep 25, 2015 at 20:04

1 Answer 1

2

You can try:

$(".weekHourValue[data-month='5'][data-day='10']").each(function(){ if (!$(this).find(".singleYearEvent").length) $(this).append("<div class='singleYearEvent'></div>"); }); 
Sign up to request clarification or add additional context in comments.

2 Comments

Not really, because there is no need to iterate/manipulate the filtered collection afterwards.
Ok thank, you I thinked that JQuery have somethink like where this not in parrent

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.