I hope I get your point correctly.
JS
var t = document.getElementsByClassName('test1')[0];
var b = document.getElementsByTagName('input')[0];
t.onmouseover = function(e){
this.className += ' testHover';
}
t.onmouseout = function(e){
this.className = this.className.replace(' testHover','');
}
b.onmouseover = function(e){
var p = document.getElementsByClassName('test1')[0];
p.className += ' testHover';
}
b.onmouseout = function(e){
var p = document.getElementsByClassName('test1')[0];
p.className = p.className.replace(' testHover','');
}
The above code in object form:
var obj = {
initialize: function () {
this.t = document.getElementsByClassName('test1')[0],
this.b = document.getElementsByTagName('input')[0]
this.attachEvents();
},
addClass: function () {
this.t.className += ' testHover';
},
removeClass: function () {
this.t.className = this.t.className.replace(' testHover', '');
},
attachEvents: function () {
var t = this.t;
var b = this.b;
t.onmouseover = this.addClass.bind(this);
t.onmouseout = this.removeClass.bind(this);
b.onmouseover = this.addClass.bind(this);
b.onmouseout = this.removeClass.bind(this);
}
};
obj.initialize();