The following works in all browsers except IE 9.0.8. It loads a survey form within div with an ajax request.
$('.tab-content').on('click', '.show_survey_form', function(e) {
e.preventDefault()
target = $(this).attr("data-target")
my_href = $(this).attr("href")
console.log("load: " + target + " target: " + my_href)
// load: #survey_response_form_33 target: /surveys/33/survey_responses/edit_multiple
// Don't make a request unless the form is opening.
if ($(this).hasClass('collapsed')) {
console.log("Making request!")
//$(target).load(my_href)
$(this).html(closeSurveyForm) // Just changes the language on the button
} else {
$(this).html(respondToSurvey) // Just changes the language on the button
}
}
The .load is commented out during debugging. IE seems to have a problem using .hasClass in this context. It's used elsewhere with no issue.
The really odd part is that the moment I open the dev tools window, it starts working. It consistently doesn't work before then, and consistently works after hitting F12.
Other issues have said the hasClass method doesn't work when the class contains a \r char but that isn't the case here. I'm using jQuery 1.8.3.
Update: Changing the href to "#" and writing the URL into data-load had no effect. Still works in all browsers except IE 9.0.8.
console.log
not working until F12 is opened. See this question for a full answer – Owconsole
calls? because that bit about the dev tools makes it sound like a pretty classic case of the "console not defined" issue. – Owconsole
object until F12 is opened, so if you haveconsole.log
in the code and don't open F12, then it will fail in exactly the way you describe. You're right that the console isn't the focus of the problem, and you're also right that usingalert()
instead has other issues when testing async code, but I think if you remove your debugging code entirely, it will work. If I'm wrong about that, then I don't know what the problem is, but post a jsfiddle example and I'll see if I can work it out (if I have time!). – Ow