views:

44

answers:

2

Hello, I have simplified my page and here what I have:

<html>
<head>
<meta http-equiv="content-type" content="text/plain; charset=utf-8" />
<title>Title</title>
<style>
    a {
        text-decoration: none;
    }

    div select {
        margin-top: 20px;
        display: block;
    }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;
<script>
    $('div').click(function(){
                        return false;
                        });
</script>


</head>

<body>
<a href="#############">
<img src="preview_image" />
    <div>
        <input type="text" value="" />
        <select>
            <option value="default" selected>choose</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
    </div>
</a>
</body>
</html>

The main idea is that I have a "A" hyperlink tag, inside which is included DIV with INPUT and SELECT inside.

What my goal is: when I put text into INPUT and when I select option from SELECT - the parent A hyperlink should not trigger.

I have tried to fix it with "return false", but looks this is not helping.

Also I have some problem in Mozilla FF: SELECT is not choosing any value whatever you choose there in the list. It is always left as "choose"


UPD

the only problem left is the SELECT behavior inside A-hyperlink in FireFox. I have FF version 3.6.3 And the behavior is when I select option from SELECT it is not set as chosen. In all the rest browsers seem to work correctly.

A: 

Even if I don't know, what you need your entire <a><div>... construct for, in any case you should put your script into a ready() block, so that it executes when the page is loaded:

$(document).ready(function(){

   $('div').click(function(){
        return false;
   });

});
Chris Lercher
thanks.But in the firefox, while it stopping the A-link to go, the value in the SELECT list is not chosen. I have wrote about it in the initial.It is always left as "choose".
@volder: That won't work. It's simply not designed to work. Change the structure, at the end of the day, it will save you a lot of time and headache.
Chris Lercher
ok, thanks for the advice
A: 

The problem with your approach: everything is contained in this link element. So theoretically, a browser is right to assume that anything that gets clicked inside this A-tag is clicking the link. Even thought this may work differently for some browsers, and lead to the behaviour you would like, I would doubt that the behaviour is consistent over all user agents. Hence I don't see how there is any way to make this work reliably without getting rid of the A-element, respectively moving the A-element so its only around the image (which is the behaviour you desire):

<a href="#############">
   <img src="preview_image" />
</a>
<div>
   <input type="text" value="" />
   <select>
            <option value="default" selected>choose</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
   </select>
</div>
inflagranti
the problem is that this DIV is added through JS on page load. And it is added to every image. Images sometimes are wrapped with A and sometimes are not. So for general purpose the DIV was added after every image, because of this it is sometimes inside A-tag and sometimes not.Actually, the answer in the previous post is stopping A-tag following. But there is another problem in FireFox, where there is some problem with choosing value in SELECT element inside A-tag. It is simply not chosen.If you have any advice on this - I would appreciate. Tnx.
Can't you change the script to add the div after the surrounding a-tag instead of directly after the immage?
inflagranti
This is the way it should be done in the proper way. And choosing this way means to overwrite a lot of code, which I got from other developer. If there is no other way, of course, I will do this, but I have some deadlines and would like to avoid this if it is possible.
As I said, I dont see how this will work properly across all current (and future Browsers). As Chris_I wrote: start redesigning it now, it will have to be redesigned eventually anyway.
inflagranti
ok, thanks. This is what I've already started.