Having read up on it and having been "told off" several times for using live
as opposed to on
I am moving all my code over to on
... and having loads of trouble!!
Most of it I have overcome, but today I have a very strange issue.
I have a question/answer bulletin board thing where the message headers are shown but content is loaded dynamically when clicking a header, the HTML is
<div class="headerRow" id="header_<%# Eval("headerId")%>">
<span class="delete" id="delete_<%# Eval("msgId")%>"></span>
<span class="markClosed" id="close_<%# Eval("headerId")%>"></span>
<span id="view_<%# Eval("msgId")%>" class="openCurrent">
<span class="customerData userCol">
<span class="qName"><%# Eval("customerName")%></span>
<span class="qEmail">(<%# Eval("email")%>)</span>
</span>
<span class="subjectCol"><%# Eval("subject")%></span>
<span class="timeCol"><%# Eval("dateTime")%></span>
</span>
<span class="reply" id="reply_<%# Eval("msgId")%>"> Reply </span>
</div>
So we have a headerRow
container, within which are some buttons to close or delete the message thread, and then a span
containing the details of the message, user name, email subject, and then a button to press to opena reply form.
The span with class openCurrent
has a jQuery on binding as follows:
$('body').on('click', '.openCurrent', function (e) {
var msgid = extractNumbers($(this).attr('id')); // sub function to pull the message ID from the element ID
if ($('#content_' + msgid).html() == '') {
$(but).addClass('centreLoader');
getMsgContent(msgid, 'absolute', function (result) {
// getMsgContent is an AJAX call returning the message
$('#content_' + msgid).html(result).slideToggle();
});
} else {
$('#content_' + msgid).slideToggle();
};
});
Now, this works perfectly on my PC, but is unreliable on an iPad.
It SOMETIMES works, and I can't figure out any pattern as to why/when it will work.
I did initially have the on
bind look like this:
$('.headerRow').on('click', '.openCurrent', function (e).....
But after reading about a bug in mobile Safari, here:
jQuery .on() and .delegate() doesn't work on iPad
I changed it to the body, but it made no difference to behaviour.
I've also noticed previously that mobile Safari won't trigger click
events unless the element has CSS cursor:pointer
in this case, I have that already in place as it makes sense visually on the desktop GUI.
Anyone got any ideas?
EDIT:
It doesn't work in Chrome on iPad either!
Additional Edit:
I have also tried binding the click event to the headerRow
element, but get the same problem