0

Possible Duplicate:
Fade HTML element with raw javascript

Any one Know Javascript trick to do this ? Actually I dont want any other libraries to do this..

Community
  • 1
  • 1
raas_admin
  • 15
  • 4

2 Answers2

0

Not sure but this code should help ya

document.getElementById('ELEMENT-ID').style.opacity = 0.4;
document.getElementById('ELEMENT-ID').style.filter = "alpha(opacity=40)";

You may use

getElementsByTagName("div") or getElementsByClassName("CLASS-NAME") to filter ahead.

Cheers!

Abbas
  • 6,720
  • 4
  • 35
  • 49
foxybagga
  • 4,184
  • 2
  • 34
  • 31
-1

What is the one that you don't want to fade?

if it's the one that got a click, let's imagine:

<div id="container">
   <ul>
       <li>Item 1</li>
       <li>Item 2</li>
       <li>Item 3</li>
       <li>Item 4</li>
       <li>Item 5</li>
   </ul>
</div>

and you have hooked up the click event to all li elements

$("#container li").click(function() { });

you can simple do:

$("#container li").click(function() { 
    $("#container li").not(this).fadeIn();
});

live example with opacity

without any framework to help you out, you will end up writing a lot of code...

for example you can see that only to hook up the onDomReady is a lot awful code in this answer

javascript domready?

And worst that all this, is that you need to write code to each browser version, as there are so many engines and the same code will never work on all of them, the big question is:

Do you really want to go without jQuery?

Community
  • 1
  • 1
balexandre
  • 73,608
  • 45
  • 233
  • 342
  • As long as you provide reasons for why jQuery should be used, it's fine. But you didn't when I wrote my comment. Although I think that DOM ready is not an argument. You can always put your code at the end of the `body` which will be sufficient for most situations. And as you may have seen in the question in linked to as duplicate, writing your own simple fade script is actually not that difficult (though it might not be x-browser compatible). Of course jQuery provides many more features in this regard. – Felix Kling Jan 14 '12 at 10:34