QUESTION: preventDefault()
isn't preventing a sign out
link getting called.
TESTED:
- the block is getting called. I put in an
alert()
in thepreventDefault
block, and it indeed gets called
OTHER:
- it does work for other links on the page, such as a
next page
link.
function promptForUnsavedWork() {
if ($('#reading_connection_content').length > 0) {
$('a').on('click', function (e) {
$('.notebook_save_button_js').each(function(){
if ($(this).attr('data-dirty') == 'true' && $(this).text() ==
"Save Your Answer"){
$(this).closest('.connection_question_container').addClass('highlight');
var confirmation_answer = confirm("You have unsaved work. Are
you sure you want to leave?");
if (confirmation_answer) {
} else {
e.preventDefault();
}
}
});
<li class="sign_out gear_item"><%= link_to "Sign Out",
destroy_student_session_path, method: "delete", class: "gear_link", :id
=> "sign_out_link" %></li>