I cannot access element (Child) but it exists (fullCalendar)

Asked

Viewed 23 times

0

Using the function eventAfterRender I’m trying to access a child element that exists, but using the function find(), apparently not. Through the console, I can navigate to the child element as follows:

[0] (a.fc-time-grid-event.fc-v-event.fc-event.fc-start.fc-end.clicavel.rede)
 children
  [0] (div.fc-content)
   children
    [0] (div.fc-title)
     children
      [0] (img) <- esse é o elemento em questão

I tried in the following ways, but without success:

$(element).find('img');
$(element).find('.fc-title').child().first();

Using the second attempt, I can get to the . Fc-title element only, normally returning the element ($(element).find('.fc-title'))

Remembering that the image element was added by the event title (Events)

1 answer

0

I arrived at a bizarre solution and, from what I realized, at the moment I was trying to use the find(), the element had not yet been rendered (I didn’t understand it correctly), I used the function setTimeout() passing as time 0 (I did not understand right²) and apparently solved:

setTimeout(() => {
    $(element).find('img');
}, 0);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.