javascript - JQuery - Script working in everything except IE10 -


i have here fiddle problem.

the script makes use of bunch of cool functions, nothing on ie10.

i don't know 1 part of disagrees with, there javascript debugger available ie10 or can see i'm doing wrong?

$(function (){     $('.rolecheck').click(function () {         var check = $(this).attr('id');         var id = check.substr(check.length - 1).tostring();         var field = "#fieldset" + id;         var oldcol = $(this).css("background-color");         if (oldcol == "rgb(139, 231, 156)") {             $(this).css("background-color", "#fc8b6a");             $(field).hide();             $(this).find('span').text("show");         }         else {             $(this).css("background-color", "#8be79c");             $(field).show();             $(this).find('span').text("hide");         }     }); }); 

here trimmed down version of used:

<div id="columns">     <div class="columns left">         <fieldset>             <legend>filters , controls</legend>             <div class="rolecheck" id="check0">                 <span>hide</span> engineer             </div>             <br />             <div class="rolecheck" id="check1">                 <span>hide</span> trainee engineer             </div>             <br />             <div class="rolecheck" id="check2">                 <span>hide</span> senior engineer             </div>         </fieldset>     </div>     <div class="columns right">         <fieldset id="fieldset0">             <legend>engineer</legend>             <table>                 <thead>                     <tr>                         <th>header 1</th>                         <th>header 2</th>                     </tr>                 </thead>                 <tbody>                     <tr>                         <td>info 1</td>                         <td>info 2</td>                     </tr>                 </tbody>             </table>         </fieldset>         <fieldset id="fieldset1">             <legend>trainee engineer</legend>             <table>                 <thead>                     <tr>                         <th>header 1</th>                         <th>header 2</th>                     </tr>                 </thead>                 <tbody>                     <tr>                         <td>info 1</td>                         <td>info 2</td>                     </tr>                 </tbody>             </table>         </fieldset>         <fieldset id="fieldset2">             <legend>senior engineer</legend>             <table>                 <thead>                     <tr>                         <th>header 1</th>                         <th>header 2</th>                     </tr>                 </thead>                 <tbody>                     <tr>                         <td>info 1</td>                         <td>info 2</td>                     </tr>                 </tbody>             </table>         </fieldset>     </div> </div> 

ah perils of programming using chrome default browser...

i figured out why script wasn't working in ie10! :d

there 2 reasons:

when call code:

var oldcol = $(this).css("background-color"); 

ie returns hex value first (in case #8be79c)

then subsequent calls script return rgb value (rgb(139,231,156)) (note lack of whitespace) weird right?

when wrote script, used alert() find out colour returned .css(), gave me rgb(139, 231, 156) (from chrome, whitespace!) that's script looking out for.

replacing:

var oldcol = $(this).css("background-color"); if (oldcol == "rgb(139, 231, 156)") { 

with:

var oldcol = $(this).css("background-color").replace(/ /g,''); if (oldcol == "rgb(139,231,156)" || oldcol == "#8be79c") { 

means works time in both chrome , ie 10.

hopefully helps else happens come across rather unusual problem.

thanks helpful comments debugging, helped me figure out problem!


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -