I need to convert JQuery code to Prototype. I have already done so by putting bits and pieces together, but my code does not work correctly in IE. The piece of code hide/show columns in a 3-column layout. Here is the code:
HTML:
Code:
<div id="layout-switcher" class="info">
<p class="switch"><strong>Toggle to change the layout:</strong>
<a id="toggle_a" href="#">hidecol1</a> |
<a id="toggle_b" href="#">hidecol2</a> |
<a id="toggle_c" href="#">hideboth</a>
</p>
</div>
JQuery:
Code:
$(document).ready(function(){
$('#js-info').hide();
$('#layout-switcher p.switch').show();
$('a[id*=toggle]').click(function(){
if ($(this).hasClass('active') === true) {
$('a').removeClass('active');
$('body').removeAttr('class');
} else {
$('a').removeClass('active');
$('body').removeAttr('class').addClass($(this).text());
$(this).addClass('active');
}
});
$('#toggle_linear').hide();
});
Prototype:
Code:
document.ready(function(){
$('js-info').hide();
$('layout-switcher').select('p.switch').first().show();
$$('a[id*="toggle"]').each(function(elt) {
Event.observe(elt, 'click', function(event) {
Event.stop(event);
if ($(this).hasClassName("active") === true) {
$$('a').invoke('removeClassName', 'active');
$(document.body).removeAttribute('class');
} else {
$$('a').invoke('removeClassName', 'active');
$(document.body).removeAttribute('class');
$(document.body).addClassName($(this).innerHTML);
$(this).addClassName('active');
}
});
});
});
Prototype code is my attempt to change the original JQuery code. In Firfox this thing works; in IE clicking the toggle link does not show the div once it is hidden. Thank you for your help.