Skip to main content

Posts

Showing posts from July, 2010

jquery - the trigger method

Having recently had to work on a client website where jquery wasn't available, it was really apparent just how useful this library is and how pleasureable it makes working with JavaScript. Having to resort back to getElementById and getElementsByClassName was painful in comparison.

Today I discovered and made use of yet another useful feature - the trigger method which enables an action on one element to fire the functions associated with events on another.

I had a simple accordion style user interface that looked like this:



On clicking the cross on the right a panel below would expand and display the content.

The mark-up looked like this:

    1<ulid="list">
    2<li>
    3<divclass="head">Title</div>
    4<ahref="">+</a>
    5<ul>
    6<li>Content one</li>
    7</ul>
    8</li>
    9</ul>

And I had a function that carried out the toggling of the display like this:

    1 $("#content ul.lis…