mmmm
mmmm

Reputation: 3938

jQuery click (only click) not working

So here is the jQuery code (as simple as possible) :

$(document).ready(function(){    
$("#test").click(function () {
    alert('Works!');
  });
});

and the page:

<script type="text/javascript" src="jquery-1.6.4.min.js" ></script>
<script type="text/javascript" src="test.js" ></script>
<p id="test">ss</p>

and funny thing, whatever I put after click(), doesn't work, BUT if I use hide(), append() or whatever instead of click(), it is working. What is the problem? I'm using the SMARTY, I simplified the code a little, because this page is included into layout.tpl but nevertheless; why only click() function doesn't work?!

Upvotes: 2

Views: 141

Answers (1)

Subedi Kishor
Subedi Kishor

Reputation: 5996

The problem you are getting is with the CSS positioning of the elements.

The div with id menu is stacked over the div with the id strona as the former have given width 200px and position:absolute. So the click on the text is not working but the click on the div further right of text is working.

So in this case if you add

`position:absolute`

to the div strona, it works as expected.

Check the updated fiddle here.

Upvotes: 1

Related Questions