Posts tagged ‘javascript’

May 19th, 2010

Change the background of many div on a rollover

First you need a method to change the background of a div :


function changeDivBkg(divId, imgSrc) {
document.getElementById(divId).style.backgroundImage = 'url(' + imgSrc + ')';
}

After that change the onMouseOver content of a div like that :


<div onMouseOver="changeManyDivBkg()">

Now the easy part, you can add so many lines as needed :


function changeManyDivBkg() {
changeDivBkg('divId1', 'image1.jpg');
changeDivBkg('divId2', 'image1.jpg');
}
May 19th, 2010

Verify an email with javascript

This method use a regular expression :


function VerifMail(mail)
{
var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}, 'i');
if(reg.test(mail))
return true;
else
return false;
}
Tags: