Wissem Achour
Wissem Achour

Reputation: 197

How to get parent's children in jquery?

this is my HTML file :

<a class="fc-time-grid-event fc-event fc-start fc-end fc-draggable fc-resizable" style="top: 703px; bottom: -791px; z-index: 1; left: 0%; right: 0%;">

 <div class="fc-content"><div class="fc-time" data-start="4:00" data full="4:00 PM"><span>4:00</span></div>
   <div class="fc-title">Work Order 1003</div>
    <div class="fc-bg"></div>
     <div class="fc-resizer"></div>

</a>

I got the children content 'div.fc-title' using this code line $('div').on('click', 'div.fc-content', function(e) { alert($(this).children('.fc-title').text())

On the other hand, I couldn't get it from the parent 'a' down to 'fc-title'.

Upvotes: 0

Views: 65

Answers (2)

Mayank Tripathi
Mayank Tripathi

Reputation: 1342

A minor modification to your script and it's done!

JS:

$('a').on('click', function(e) {
e.preventDefault();
alert($(this).children('.fc-title').text());
});

Fiddle here...

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

You could try to bind the handler to document object instead

$(document).on('click', 'div.fc-content', function (e) {
    alert($(this).children('.fc-title').text())
})

Demo: Fiddle

Upvotes: 1

Related Questions