Re: [jQuery] Disabling a tags

2006-12-13 Thread Sam Collett
On 13/12/06, Brice Burgess [EMAIL PROTECTED] wrote:
 Joan Piedra wrote:
 
  On 12/12/06, *Aaron Heimlich* [EMAIL PROTECTED]
  mailto:[EMAIL PROTECTED] wrote:
 
 
  div#myid = SLOW!!
 
  #myid = FAST!!
 
  .myclass = SLOW!!
 
  div.myclass = FAST(er)!!
 
 
 
 
  LOL, I think this is how it works in real CSS.
 
  div#myid = Faster
  #myid = Slow
  .myclass = Slow
  div.myclass = Fast
 Does anyone know of CSS best practice benchmarks? Is div#myid indeed
 faster in CSS?

 ~ Brice

I don't know if you can even benchmark the CSS parsing speed of
browsers. It's so fast that you don't notice anyway (and if you do, it
is probably due to the stylesheet downloading slowly or the page being
very big).

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


Re: [jQuery] Disabling a tags

2006-12-12 Thread David Duymelinck
Sam Collett schreef:
 That prevents the link being followed, but still keeps the href the
 same (incase you want to enable it again). Also, I think it is better
 performance wise to use '#myid' rather than 'div#myid'
I thought div#myid was less generic than #myid so that the performance 
would improve using something like that. #myid could match a form, a div 
or some other tag you apply the id to.

-- 
David Duymelinck

[EMAIL PROTECTED]


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


Re: [jQuery] Disabling a tags

2006-12-12 Thread Klaus Hartl
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/


Re: [jQuery] Disabling a tags

2006-12-12 Thread Aaron Heimlich

On 12/12/06, David Duymelinck [EMAIL PROTECTED] wrote:


I thought div#myid was less generic than #myid so that the performance
would improve using something like that. #myid could match a form, a div
or some other tag you apply the id to.



This might be true in CSS, but when jQuery sees something like #myid, it
turns that into document.getElementById(myid) which is very fast.

I can't say for sure, but I think that if jQuery saw something like
div#myid, it would do document.getElementsByTagName(div) and then
document.getElementById(myid)

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Disabling a tags

2006-12-12 Thread Klaus Hartl
Aaron Heimlich schrieb:
 On 12/12/06, *David Duymelinck* [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 I thought div#myid was less generic than #myid so that the performance
 would improve using something like that. #myid could match a form, a div
 or some other tag you apply the id to.
 
 
 This might be true in CSS, but when jQuery sees something like #myid, 
 it turns that into document.getElementById(myid) which is very fast.
 
 I can't say for sure, but I think that if jQuery saw something like 
 div#myid, it would do document.getElementsByTagName(div) and then 
 document.getElementById(myid)


I think it's even worse. It has to go through all the divs and check the 
id...
document.getElementById cannot be used for such a list returned by 
document.getElementsByTagName(div).


-- Klaus


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


Re: [jQuery] Disabling a tags

2006-12-12 Thread Aaron Heimlich

On 12/12/06, Klaus Hartl [EMAIL PROTECTED] wrote:


I think it's even worse. It has to go through all the divs and check the
id...
document.getElementById cannot be used for such a list returned by
document.getElementsByTagName(div).



Yeesh!

NOTE TO ALL:

div#myid = SLOW!!

#myid = FAST!!

.myclass = SLOW!!

div.myclass = FAST(er)!!

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Disabling a tags -- thanks

2006-12-12 Thread Bruce MacKay
Thank you all for the solutions and the additional lesson about 
div#myID - much appreciated.

-- Bruce


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


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


Re: [jQuery] Disabling a tags

2006-12-12 Thread Choan C. Gálvez
On 12/12/06, Aaron Heimlich [EMAIL PROTECTED] wrote:
 On 12/12/06, Klaus Hartl [EMAIL PROTECTED] wrote:
  I think it's even worse. It has to go through all the divs and check the
  id...
  document.getElementById cannot be used for such a list returned by
  document.getElementsByTagName(div).
 

 Yeesh!

 NOTE TO ALL:

 div#myid = SLOW!!

 #myid = FAST!!

 .myclass = SLOW!!

 div.myclass = FAST(er)!!

#foo #bar = BUGGY!!

-- 
Choan
http://choangalvez.nom.es/

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


Re: [jQuery] Disabling a tags

2006-12-12 Thread Joan Piedra

On 12/12/06, Aaron Heimlich [EMAIL PROTECTED] wrote:



div#myid = SLOW!!

#myid = FAST!!

.myclass = SLOW!!

div.myclass = FAST(er)!!





LOL, I think this is how it works in real CSS.

div#myid = Faster
#myid = Slow
.myclass = Slow
div.myclass = Fast

Cheers

--
Joan Piedra || Frontend webdeveloper
http://joanpiedra.com/
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Disabling a tags

2006-12-12 Thread Brice Burgess
Joan Piedra wrote:

 On 12/12/06, *Aaron Heimlich* [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:


 div#myid = SLOW!!

 #myid = FAST!!

 .myclass = SLOW!!

 div.myclass = FAST(er)!!


  

 LOL, I think this is how it works in real CSS.

 div#myid = Faster
 #myid = Slow
 .myclass = Slow
 div.myclass = Fast
Does anyone know of CSS best practice benchmarks? Is div#myid indeed 
faster in CSS?

~ Brice

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