[Proto-Scripty] Re: Element.select works wrong when select tag a

2010-07-17 Thread Quyết Tiến
I do this:
$('content').select('a[rel=dhtmlwindow]').each(function(anchor) {
anchor.observe('click', function() { alert (''); });
})

But it does not work again.

On Jul 17, 8:29 am, T.J. Crowder t...@crowdersoftware.com wrote:
 Hi,

  So from now with tag a, I must use like this
  Object.prototype.toString.call(anchor)) to get object.

 No, you already _have_ an object. It's just that when you do this:

     alert(anchor);

 ...it's exactly like doing this:

     alert(anchor.toString());

 ...because `alert` does an implicit toString operation on whatever
 you pass into it, and the toString operation of an HTMLAnchorElement
 returns its href.

 Presumably you don't actually want to do an alert. You can do anything
 else with the object you like.  For instance, if you wanted to remove
 the anchor:

     anchor.remove();

 ...or if you wanted to give it a green background:

     anchor.setStyle({backgroundColor: green});

 ...etc., etc.

 `Object.prototype.toString.call(x)` is useful for testing the _type_
 of an object, because its return value is well-defined by the spec and
 a bit more specific than `typeof` (although `typeof` is also quite
 useful). But that's a side point; my main point was that the thing
 being passed into your function _is_ the anchor object, not just its
 href string.

 HTH,
 --
 T.J. Crowder
 Independent Software Consultant
 tj / crowder software / comwww.crowdersoftware.com

 On Jul 17, 12:48 am, Quyết Tiến doquyett...@gmail.com wrote:



  So from now with tag a, I must use like this
  Object.prototype.toString.call(anchor)) to get object.

  On Jul 16, 10:42 pm, T.J. Crowder t...@crowdersoftware.com wrote:

   Hi,

But it doesn't work, it returns href of tag a instead a object.

   Actually, it does work -- it's just that the default behavior of the
   HTMLAnchorElement when you try to use it as a string is to return the
   href (e.g., the result of its toString method), and `alert` does
   exactly that. You can see that it's an anchor element by changing your
   function:

       $('content').select('a[rel=dhtmlwindow]').each(function(anchor)
   {
           // alerts typeof = object
           alert(typeof =  + typeof anchor);

           // alerts Object.toString = [object HTMLAnchorElement]
           alert(Object.toString =  +
   Object.prototype.toString.call(anchor));

           // alerts HTMLAnchorElement.toString = (the href)
           alert(HTMLAnchorElement.toString =  + anchor.toString());
       });

   HTH,
   --
   T.J. Crowder
   Independent Software Consultant
   tj / crowder software / comwww.crowdersoftware.com

   On Jul 16, 7:37 am, Quyết Tiến doquyett...@gmail.com wrote:

I have a page html like this:
div id=content style=padding: 100px;
a href=# rel=dhtmlwindowcontent/a
div rel=dhtmlwindowcontent/div
a href=# rel=dhtmlwindow;content/a
a href=# rel=dhtmlwindowcontent/a
/div

I want to select all tag a has rel is dhtmlwindow and this is code:

$('content').select('a[rel=dhtmlwindow]').each(function(anchor) {
alert (anchor);

});

But it doesn't work, it returns href of tag a instead a object.- Hide 
quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Element.select works wrong when select tag a

2010-07-17 Thread T.J. Crowder
Hi,

 But it does not work again.

It does for me, if I fix the various typos in the HTML:
http://jsbin.com/eweyo4

Doesn't work is not really a useful description of a problem. When
describing a problem for people to help with, these are the sorts of
questions you typically want to answer: Doesn't work *how*? What
happens? What do you expect to have happen instead? Do you see any
errors? If so, what are they? What have you already checked to try to
figure it out? Etc., etc.

You probably want to walk through the code in a debugger like Firebug
(for Firefox), Dev Tools (for Chrome; built in), VS.Net or Script
Debugger (for IE), etc., to figure out what's going wrong on the page.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On Jul 17, 4:45 pm, Quyết Tiến doquyett...@gmail.com wrote:
 I do this:
 $('content').select('a[rel=dhtmlwindow]').each(function(anchor) {
     anchor.observe('click', function() { alert (''); });

 })

 But it does not work again.

 On Jul 17, 8:29 am, T.J. Crowder t...@crowdersoftware.com wrote:



  Hi,

   So from now with tag a, I must use like this
   Object.prototype.toString.call(anchor)) to get object.

  No, you already _have_ an object. It's just that when you do this:

      alert(anchor);

  ...it's exactly like doing this:

      alert(anchor.toString());

  ...because `alert` does an implicit toString operation on whatever
  you pass into it, and the toString operation of an HTMLAnchorElement
  returns its href.

  Presumably you don't actually want to do an alert. You can do anything
  else with the object you like.  For instance, if you wanted to remove
  the anchor:

      anchor.remove();

  ...or if you wanted to give it a green background:

      anchor.setStyle({backgroundColor: green});

  ...etc., etc.

  `Object.prototype.toString.call(x)` is useful for testing the _type_
  of an object, because its return value is well-defined by the spec and
  a bit more specific than `typeof` (although `typeof` is also quite
  useful). But that's a side point; my main point was that the thing
  being passed into your function _is_ the anchor object, not just its
  href string.

  HTH,
  --
  T.J. Crowder
  Independent Software Consultant
  tj / crowder software / comwww.crowdersoftware.com

  On Jul 17, 12:48 am, Quyết Tiến doquyett...@gmail.com wrote:

   So from now with tag a, I must use like this
   Object.prototype.toString.call(anchor)) to get object.

   On Jul 16, 10:42 pm, T.J. Crowder t...@crowdersoftware.com wrote:

Hi,

 But it doesn't work, it returns href of tag a instead a object.

Actually, it does work -- it's just that the default behavior of the
HTMLAnchorElement when you try to use it as a string is to return the
href (e.g., the result of its toString method), and `alert` does
exactly that. You can see that it's an anchor element by changing your
function:

    $('content').select('a[rel=dhtmlwindow]').each(function(anchor)
{
        // alerts typeof = object
        alert(typeof =  + typeof anchor);

        // alerts Object.toString = [object HTMLAnchorElement]
        alert(Object.toString =  +
Object.prototype.toString.call(anchor));

        // alerts HTMLAnchorElement.toString = (the href)
        alert(HTMLAnchorElement.toString =  + anchor.toString());
    });

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / comwww.crowdersoftware.com

On Jul 16, 7:37 am, Quyết Tiến doquyett...@gmail.com wrote:

 I have a page html like this:
 div id=content style=padding: 100px;
 a href=# rel=dhtmlwindowcontent/a
 div rel=dhtmlwindowcontent/div
 a href=# rel=dhtmlwindow;content/a
 a href=# rel=dhtmlwindowcontent/a
 /div

 I want to select all tag a has rel is dhtmlwindow and this is code:

 $('content').select('a[rel=dhtmlwindow]').each(function(anchor) {
 alert (anchor);

 });

 But it doesn't work, it returns href of tag a instead a object.- Hide 
 quoted text -

  - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: Element.select works wrong when select tag a

2010-07-17 Thread Richard Quadling
On 16 July 2010 15:42, Quyết Tiến doquyett...@gmail.com wrote:
 yes

 On Jul 16, 8:42 pm, Richard Quadling rquadl...@gmail.com wrote:
 On 16 July 2010 07:37, Quyết Tiến doquyett...@gmail.com wrote:

  a href=# rel=dhtmlwindowcontent/a

 Is that a typo?

 a href=# rel=dhtmlwindowcontent/a

 --
 You received this message because you are subscribed to the Google Groups 
 Prototype  script.aculo.us group.
 To post to this group, send email to prototype-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to 
 prototype-scriptaculous+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/prototype-scriptaculous?hl=en.



So, you've got some HTML. With errors. And you are expecting it to
work correctly.

Or have I missed something.

If a browser has to make corrections to your HTML to render it, or
just guesses as to what you mean, you can't expect the browser to read
you mind and know what you want. So when you then attempt to add
styles, observers, etc. you are pretty much standing on a house of
cards.

Clean the HTML.

What happens now.

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: Element.select works wrong when select tag a

2010-07-17 Thread Walter Lee Davis
I think the OP was saying that it was a typo in the e-mail, not that  
the original code had that same mistake and he was expecting it to  
magically work anyway. Give the guy a little credit here...


Walter

On Jul 17, 2010, at 2:53 PM, Richard Quadling wrote:


On 16 July 2010 15:42, Quyết Tiến doquyett...@gmail.com wrote:

yes

On Jul 16, 8:42 pm, Richard Quadling rquadl...@gmail.com wrote:

On 16 July 2010 07:37, Quyết Tiến doquyett...@gmail.com wrote:


a href=# rel=dhtmlwindowcontent/a


Is that a typo?

a href=# rel=dhtmlwindowcontent/a


--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.





So, you've got some HTML. With errors. And you are expecting it to
work correctly.

Or have I missed something.

If a browser has to make corrections to your HTML to render it, or
just guesses as to what you mean, you can't expect the browser to read
you mind and know what you want. So when you then attempt to add
styles, observers, etc. you are pretty much standing on a house of
cards.

Clean the HTML.

What happens now.

--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.




--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.