Hi, > TJ, you inadvertently disabled "Edit using JS Bin" for this > example :)
LOL! You're right! Just add /edit to the URL. > Who is JS Bin, is that yours? Very cool. Not mine, and in fact it drives me nuts, the editor is always getting in your way. But yes, it's a very handy way to do live examples of JavaScript, CSS, DOM. Another is jsfiddle.net. -- T.J. :-) On Sep 20, 7:13 pm, kstubs <[email protected]> wrote: > TJ, you inadvertently disabled "Edit using JS Bin" for this > example :) Who is JS Bin, is that yours? Very cool. > > On Sep 20, 5:12 am, "T.J. Crowder" <[email protected]> wrote: > > > > > Hi, > > > Not entirely sure what you're trying to do, but this will fail: > > > $(document.body).descendants().observe > > ^-- Problem here > > > `#observe` is a function Prototype adds to *elements*, not arrays. > > `#descendants` returns an array. Although you could fix this via > > `#invoke`, here's an alternative: > > > If you're trying to catch a click wherever it occurs, just watch for > > it on `document` -- the click event bubbles up the hierarchy. You can > > find out what element the click actually happened on by using the > > `Event#findElement` function. That starts with the deepest-down > > element on which the event occurred and then searches upward for the > > first element matching the selector you give it. So for example, this > > code handles a click if it occurs in any `a` element, even if it > > actually occurs in a `strong` or `span` or whatever within the `a` > > element: > > > Example:http://jsbin.com/upetu > > * * * * > > document.observe("click", function(event) { > > display("Document clicked"); > > var a = event.findElement('a'); > > if (a) { > > display("Click was anchor '" + a.id + "'!"); > > event.stop(); // Just for our purposes > > a.setStyle({backgroundColor: blue}); > > } > > > function display(msg) { > > document.body.appendChild(new Element('p').update(msg)); > > }}); > > > * * * * > > > HTH, > > -- > > T.J. Crowder > > Independent Software Engineer > > tj / crowder software / com > > www / crowder software / com > > > On Sep 20, 11:47 am, Jason <[email protected]> wrote: > > > > Hello, > > > > I am modifying this:http://cpicker.com/ > > > > I have made good progress, everything is working great. I now need to > > > make one last modification. > > > > I think I need to do something like this but I am new to prototype and > > > don't really get it. > > > > $(document.body).descendants().observe('click', function() { > > > if ($('stroke_color').getStyle('display') == 'block') { > > > if ({not a decendant of stroke_color}) { > > > $('stroke_color').hide(); > > > } > > > } > > > > }); > > > > Can anyone help please? > > > > Thanks. -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
