javascript - jQuery .removeClass() issue only in Chrome, working fine in IE11 -
i have weird issue. using removeclass
, addclass
in jquery
working fine in ie , not working expected in chrome. class getting added , removed effect not visible in chrome. while pop-ups come, on click of yes next text-box should red border , pop-up should appear border change not happening in chrome.
- on load text-box have red border.
- on click of start button, text box have no border , pop-up appears , text box gets red border.
- on click of yes, popup appears , text box gets red border.
- on click of cancel, pop-up stops , current text box has red border.
please check inserted snippet in both chrome , ie , tell why irregular behavior. below working snippet:
$(document).ready(function() { debugger; var grid = jquery('[id$="gvtest"]')[0]; var rows = grid.rows; (var k = 1; k < rows.length; k++) { var textboxinitial = jquery(rows[k]).find('input.newname'); if (textboxinitial.val() == "article1") { textboxinitial.addclass("redcolorborder"); } } }); function proceedcopyvalidation() { var grid = jquery('[id$="gvtest"]')[0]; var rows = grid.rows; (var k = 1; k < rows.length; k++) { var textboxinitial = jquery(rows[k]).find('input.newname'); if (textboxinitial.hasclass("redcolorborder")) { textboxinitial.removeclass("redcolorborder"); } } (var k = 1; k < rows.length; k++) { var textbox = jquery(rows[k]).find('input.newname'); var newname = textbox.val(); var isvalid = newname == "article1" ? true : false; if (isvalid == true) { textbox.addclass("redcolorborder"); var confirm = disp_confirm(k); if (!confirm) { return false; } else { if (textbox.hasclass("redcolorborder")) { textbox.removeclass("redcolorborder"); } continue; } } } } function disp_confirm(count) { var r = confirm("a pop-up here"); return r; }
.redcolorborder { border: solid 5px red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <head> <title></title> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge;chrome=1"> </head> <body> <form method="post" id="ctl01"> <span id="featuredcontent_label1">done here</span> <div> <table class="gridnew " cellspacing="5" cellpadding="5" rules="all" border="1" id="featuredcontent_gvtest" style="border-color:#ced1d5;width:650px;"> <tbody> <tr class="headercolor"> <th class="headercolor" scope="col">old name</th> <th class="headercolor" scope="col" style="width:15%;">new name</th> </tr> <tr> <td class="alignleft" style="width:15%;">product 1</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl02$textbox1" type="text" value="article1" id="featuredcontent_gvtest_textbox1_0" class="newname" style="width:80%;"> </td> </tr> <tr> <td class="alignleft" style="width:15%;">product 2</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl03$textbox1" type="text" value="article2" id="featuredcontent_gvtest_textbox1_1" class="newname" style="width:80%;"> </td> </tr> <tr> <td class="alignleft" style="width:15%;">product 3</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl04$textbox1" type="text" value="article1" id="featuredcontent_gvtest_textbox1_2" class="newname redcolorborder" style="width:80%;"> </td> </tr> <tr> <td class="alignleft" style="width:15%;">product 4</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl05$textbox1" type="text" value="article1" id="featuredcontent_gvtest_textbox1_3" class="newname" style="width:80%;"> </td> </tr> </tbody> </table> </div> <input name="ctl00$featuredcontent$btnstart" type="button" value="start" onclick="return proceedcopyvalidation();" id="featuredcontent_btnstart"> </form> </body>
i think doesn't work in chrome because when alert thrown blocks ui thread rest of code not executed (add/remove red border).
i fixed code work in both ie , chrome (didn't test mozilla)
see settimeout.
$(document).ready(function() { debugger; var grid = jquery('[id$="gvtest"]')[0]; var rows = grid.rows; (var k = 1; k < rows.length; k++) { var textboxinitial = jquery(rows[k]).find('input.newname'); if (textboxinitial.val() == "article1") { textboxinitial.addclass("redcolorborder"); } } }); function proceedcopyvalidation() { var grid = jquery('[id$="gvtest"]')[0]; var rows = grid.rows; $('input.newname.redcolorborder').removeclass("redcolorborder"); var fnexec = function(idx) { if (idx == rows.length) return; var textbox = jquery(rows[idx]).find('input.newname'); var newname = textbox.val(); var isvalid = newname == "article1" ? true : false; if (isvalid == true) { textbox.addclass("redcolorborder"); settimeout(function(){ var confirm = disp_confirm(idx); if (confirm) { if (textbox.hasclass("redcolorborder")) { textbox.removeclass("redcolorborder"); } fnexec(idx+1); } }, 10); } else { fnexec(idx+1); } } fnexec(1); } function disp_confirm(count) { var r = confirm("a pop-up here"); return r; }
.redcolorborder { border: solid 5px red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <head> <title></title> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge;chrome=1"> </head> <body> <form method="post" id="ctl01"> <span id="featuredcontent_label1">done here</span> <div> <table class="gridnew " cellspacing="5" cellpadding="5" rules="all" border="1" id="featuredcontent_gvtest" style="border-color:#ced1d5;width:650px;"> <tbody> <tr class="headercolor"> <th class="headercolor" scope="col">old name</th> <th class="headercolor" scope="col" style="width:15%;">new name</th> </tr> <tr> <td class="alignleft" style="width:15%;">product 1</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl02$textbox1" type="text" value="article1" id="featuredcontent_gvtest_textbox1_0" class="newname" style="width:80%;"> </td> </tr> <tr> <td class="alignleft" style="width:15%;">product 2</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl03$textbox1" type="text" value="article2" id="featuredcontent_gvtest_textbox1_1" class="newname" style="width:80%;"> </td> </tr> <tr> <td class="alignleft" style="width:15%;">product 3</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl04$textbox1" type="text" value="article1" id="featuredcontent_gvtest_textbox1_2" class="newname redcolorborder" style="width:80%;"> </td> </tr> <tr> <td class="alignleft" style="width:15%;">product 4</td> <td class="alignleft"> <input name="ctl00$featuredcontent$gvtest$ctl05$textbox1" type="text" value="article1" id="featuredcontent_gvtest_textbox1_3" class="newname" style="width:80%;"> </td> </tr> </tbody> </table> </div> <input name="ctl00$featuredcontent$btnstart" type="button" value="start" onclick="return proceedcopyvalidation();" id="featuredcontent_btnstart"> </form> </body>
regards,
thibaud p.
Comments
Post a Comment