2

I'm building a working mockup of a site design and I want the ad spaces to disappear to illustrate what the page would look like if they're empty. Can I accomplish this without having the uniquely identify each space? I was hoping this would work:

<script type="text/javascript">
    $('.adSpace').click(function() {
    $this.toggle('fast');
    });
</script>
NominalAeon
  • 593
  • 5
  • 23
  • 1
    `$this` is not defined here. The [jQuery tutorial](http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Find_me:_Using_selectors_and_events) provides a good introduction to event handling, with examples. It's worth a read (and that's what it is there for: to get you started). – Felix Kling Dec 26 '12 at 16:50
  • 1
    This should be worth reading : [what-is-the-difference-between-this-$this-and-$(this)](http://stackoverflow.com/questions/3889570/what-is-the-difference-between-this-this-and-this) – Anujith Dec 26 '12 at 16:55

2 Answers2

11

Use $(this) instead of $this. $this is not defined here.

Live Demo

<script type="text/javascript">
    $('.adSpace').click(function() {
       $(this).toggle('fast');
    });
</script>
Adil
  • 146,340
  • 25
  • 209
  • 204
3

$this is not the object. You should use $(this).

this : java-script object

$(this) : converting this to jQuery object

You can use

$('.adSpace').click(function() {
   $(this).toggle('fast');
});
GajendraSinghParihar
  • 9,051
  • 11
  • 36
  • 64