キーワードthis
は、誰がイベントをトリガーしたかを示します。この場合は、DOM Element
しかし、あなたの問題は、スタイルがundefined
初期化されていないためです。したがって、初期化していない場合でも、「ComputedStyle」を使用して現在の値を取得する必要があります。
image_element.addEventListener( "click", function( )
{
this.style.width = ( getStyle(this,'width',true) - 1 ) + 'px';
this.style.height = ( getStyle(this,'height',true) - 1 ) + 'px';
}, false );
この関数をドキュメントに添付します。
/** Get the current computed style of an element */
function getStyle(element, strCssRule, returnInt){
if(typeof element==="string"){element=document.getElementById(element);}
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(element, "").getPropertyValue(strCssRule);
}
else if(element.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); });
strValue = element.currentStyle[strCssRule];
}
if(returnInt===true){ strValue=parseInt(strValue); }
return strValue;
}