-2

I am trying to change CSS elements depending on situations used in javascript.

an example I had tried was:

if ('image'=="clicked")
{blahblahblah}

'image' would be my div id or div tag in CSS. I know in Jquery I can use $('#image').click, but I don't think it Jquery will be good for my situation.

Liam
  • 27,717
  • 28
  • 128
  • 190
Hotmanics
  • 21
  • 1
  • 3

2 Answers2

2

Consider document.querySelector. It's powerful, accepting any valid CSS selector. You can even start from another element, such as myElement.querySelector, to only get children of that element that match the selector. Very useful!

Just be aware that IE7 and below do not support this function.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
1

Assuming your id as image

document.getElementById('image').onclick = function() {
   alert("button was clicked");
}​;​
SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62