admin管理员组

文章数量:1410712

If you scroll to the end of this article you'll see this list of names:

  • Wowana
  • Oomvy
  • Exza
  • Gozer
  • Hentra
  • Molisa
  • Gizic
  • Yaberi
  • Anea
  • Dymi
  • Gibbal

Each of these list items contain an image and the link. The image associated with each li is hidden with CSS. I have been trying to setup some jQuery to so that the image shows when the link is rolled over.

Here is the code:

<li><img class="previewImage" src=".png" width="200" height="151" /><a href="names/gibbal">Gibbal</a></li>

And the simple jQuery I apply in the console to test:

$('.previewImage').show();

And the error:

TypeError: Cannot read property 'show' of null

What am I overlooking? This is driving me crazy and imagine it's something very simple.

If you scroll to the end of this article you'll see this list of names:

  • Wowana
  • Oomvy
  • Exza
  • Gozer
  • Hentra
  • Molisa
  • Gizic
  • Yaberi
  • Anea
  • Dymi
  • Gibbal

Each of these list items contain an image and the link. The image associated with each li is hidden with CSS. I have been trying to setup some jQuery to so that the image shows when the link is rolled over.

Here is the code:

<li><img class="previewImage" src="http://www.brandroot./images/brands/gibbal.png" width="200" height="151" /><a href="names/gibbal">Gibbal</a></li>

And the simple jQuery I apply in the console to test:

$('.previewImage').show();

And the error:

TypeError: Cannot read property 'show' of null

What am I overlooking? This is driving me crazy and imagine it's something very simple.

Share Improve this question asked Jun 13, 2014 at 0:52 Michael RaderMichael Rader 5,9678 gold badges37 silver badges44 bronze badges 1
  • You have multiple libraries loaded. $ is not jQuery, it's some other library (mooTools, maybe?). – Barmar Commented Jun 13, 2014 at 0:56
Add a ment  | 

1 Answer 1

Reset to default 4

For some reason, doing

jQuery('.previewImage')

worked, whereas

$('.previewImage')

is null. This might be caused by another library using the $ shortcut (prototype perhaps?). Long story short: use the first Syntax instead of $

本文标签: