Reputation: 846
I want a drop shadow to appear upon click of a image. I don't use Jquery at the moment so if possible provide a java-script solution. Heres my fiddle: http://jsfiddle.net/zUNhD/7/
I would also like for the box shadow to only be active on whatever item is Currently Selected. (the last item clicked should be the only one with the shadow)
window.onload = function(){
var box1 = document.getElementById('thumbs');
var box1Div1 = box1.getElementsByTagName('input');
var img1 = box1Div1[0]
console.log(img1);
img1.onclick = function(){
img1.setAttribute("class", "BoxShadow");
};
};
Upvotes: 1
Views: 7897
Reputation: 3872
The function hasn't been called in your code.
window.onload = function(){
var box1 = document.getElementById('thumbs');
var box1Div1 = box1.getElementsByTagName('input');
var img1 = box1Div1[0];
img1.onclick = function(){
img1.setAttribute("class", "DropShad");
};
}();
Here is the working fiddle ... http://jsfiddle.net/zUNhD/18/
Upvotes: 2
Reputation: 10070
Extending from comment:
You can use :active
selector to response to "click" event, and :focus
selector to response to, well, "focus" event:
input:active, input:focus{
box-shadow:2px 2px 2px blue;
}
Upvotes: 2
Reputation: 122906
See this jsfiddle for some simplifications of your code. The css class wasn't assigned right, it should be preceded by a dot. Put your script tag near the ending </body>
tag and use:
var box1 = document.getElementById('thumbs');
var box1Div1 = box1.getElementsByTagName('input');
var img1 = box1Div1[0]
img1.onclick = function(){
img1.className = "DropShad";
};
Upvotes: 1