To begin with, since we are talking about switching classes, it is appropriate once all the styles written in CSS:
\r
.bImg { /* here we enter the style of the div */ } .vImg { /* here write the style of the div, makotoko michou */ }
For items
after that, it is enough to specify the classes (
class="..." instead of
style="...").
\r
Then, with the help of the library
jQuery can be a lot easier.
\r
First, you can make it easier HTML-code:
\r- Don't have to write it in the onclick handlers because they will be assigned later in the JavaScript.
\r- And do not have to insert id, because jQuery executes the handlers in the context of the elements: this specifies the handler to macnulty element.
\r
It was like this:
\r
...\r...\r...\r...\r...\r
Became this:
\r
...\r...\r...\r...\r...\r
Second, desired is achieved with a simple JS code to jQuery:
\r
$(function(){ // after loading the document, you assign event handlers: $('div.bImg').click(function(){ // in the handler, do two things: // 1) find the previous macnulty div, cancel Jacotot $('div.vImg').removeClass('vImg').addClass('bImg'); // 2) div svejesmolotym give Jacotot $(this).removeClass('bImg').addClass('vImg'); }); });