Bruce MacKay schrieb:
> Hello folks,
> 
> Another simple question I'm sure.  I have a preview page in which I want 
> to display the text of a tags, but to disable the tag by changing its 
> href contents to #.
> 
> The code I use to populate the div (#preview) after an ajax call is....
> 
> function showResponse(json) {
>     if (json.fields) {
>         for (var i = 0; i < json.fields.length; i++) {
>             var field = json.fields[i];
>             $("#theIndicator").hide();
>             switch(field.yesno) {
>             case "Y":
>                 $("div#preview").html(field.preview);
>                 $("div#preview a").href('#');
>                 
> $("div#content_editor").highlightFade({color:'yellow',speed:2000,iterator:'sinusoidal'});
>                 $("#sMoreLinks, #sMoreLinksText, #sMoreLinksDesc").val('');
>                 $('#sMoreLinksAction').val("add")
>                 $("#sMoreLinksDiv").html(field.linktable);
>                 break;
>             case "N":
>                 
> $("div#content_editor").highlightFade({color:'red',speed:2000,iterator:'sinusoidal'});
>                 
> $('#links_fback').html(field.message).addClass("error").show();
>             }
>         }
>     }
> }
> 
> My attempt ($("div#preview a").href('#');) does not work - I don't 
> understand why it doesn't.   Any suggestions/insights?
> 
> Thanks,
> 
> Bruce


Bruce, don't know why it doesn't work... But for disabing I recommend 
using "return false" anyway. If the page is scrolled down a little bit 
and you would click on such a link, the page would scroll to the top:

My proposal (plus a little optimization):

$("#preview").html(field.preview).find('a').click(function() {
     return false;
});

Note that "div#preview" will be slower than "#preview", because in the 
first case all divs in the DOM tree have to be searched and then the one 
with the proper id instead of immediatly using document.getElementById. 
It's the other way round with classes (always prefer "div.theClass" over 
".theClass").

-- Klaus


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to