1

I have the div event_wrapper that can be dynamically added on a page by clicking the link in add-event. The user can delete/add these divs as many times as they want. If the user chooses to delete all of these event_wrapper divs, I want to change the text inside add-event. Here is the HTML:

<div class="event_wrapper">
    <div class="event">
        <div class="well darkblue-background pull-left">
            <a class="close tooltip" data-tooltip="Delete this event"><i class="icon-remove"></i></a>
        </div>
    </div>
</div>


<div class="add-event pull-left">
    <a href="javascript:void(0);"> And Then...</a>
   </div>

(I am using jQuery) I tried using :empty selector, but it does not seem to be working. Any suggestions? Thanks!

Pete
  • 57,112
  • 28
  • 117
  • 166
Mac10
  • 145
  • 4
  • 15
  • please give some code samples. If you want change text inside add-event $(".add-event").children('a').html("Your text"); – Dineshkani Feb 06 '13 at 16:30
  • are you wanting to check if there is the event_wrapper div or divs inseide the event_wrapper? – Pete Feb 06 '13 at 16:42

3 Answers3

1

Have a look at - https://stackoverflow.com/a/3234646/295852

And then use contentChange() like:

$('.event-wrapper').contentChange(function(){
    if($(this).children().length > 0){
        // events exist
        $(".add-event pull-left").children('a').html('And Then...');
    } else {
        // no events
        $(".add-event pull-left").children('a').html('your text');
    }
});
Community
  • 1
  • 1
boz
  • 4,891
  • 5
  • 41
  • 68
0
if(!$(".event_wrapper")){
    $(".add-event pull-left").html("Whatever text you want here"); //changes the text of the div
     //or
    $(".add-event pull-left").children('a').html("whatever text you want here"); //changes the text of the anchor child
}
Ryan
  • 5,644
  • 3
  • 38
  • 66
0
  if($(".event-wrapper").html() == null) {//looking inside event-wrapper; if it contains any thing
    $(".add-event a").html("whatever");
  }
Ace Dimasuhid
  • 1,032
  • 11
  • 33