Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] how to work with html elements that have class X

Expand Messages
  • Satyam
    YAHOO.util.Dom.getElementsByClassName( class-name , img , where-to-start-from, function(el) { el.setAttribute( ... whatever ... ); // or: el.attribute =
    Message 1 of 2 , Aug 18, 2008
    • 0 Attachment
      YAHOO.util.Dom.getElementsByClassName('class-name', 'img',
      where-to-start-from, function(el) {
      el.setAttribute( ... whatever ... );
      // or: el.attribute = whatever;
      });

      You can use this for any attributes, but it is not a good idea to add
      event handlers this way. It is much better instead to add a single
      event handler for, say, 'click' to a container for the whole set of
      images and in the event listener, check what was clicked and act
      accordingly. That is called event delegation. See:

      http://developer.yahoo.com/yui/examples/event/event-delegation.html
      and:
      http://icant.co.uk/sandbox/eventdelegation/

      Satyam


      mokhtarali2001 wrote:
      > Hi
      >
      > im asking about if i can search the html elements and add an attribute
      > to it
      > ex. search for images that has class X and add onclick attribute some
      > specific code
      >
      > is there any js code that can do that?
      >
      > thanks in advance.
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      >
      > No virus found in this incoming message.
      > Checked by AVG - http://www.avg.com
      > Version: 8.0.138 / Virus Database: 270.6.4/1615 - Release Date: 16/08/2008 7:11
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.