logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 10-14-2010, 09:22 AM   #1
Rob_Che
Rob_Che's Avatar
 
Join Date: Feb 2008
Posts: 1,552
Default Useful jQuery Scripts

There are some scripts that I use ALL the time - on pretty much every site I build...

Here's one for starters.

Make a full <li > block a clickable area.
So - you have a list recent blog posts (or any list) and they are built of a few elements (image, title, brief description etc) but you want the whole thing to be clickable.

Try this:

HTML:
Code:
<ul id="myList">
     <li>
          <img src="/image.gif">
          <p>
               <strong>Title</strong>
               Some text
               <a href="#">READ MORE</a>
         </p>
     </li>
</ul>
So, you can see we have four elements in that <li> - but what if a user clicks the image or the title? I guess we could give them ALL link tags but that seems a bit heavy handed - so...

Code:
<script type="text/javascript">
$(document).ready(function(){
          $("#myList li").click(function(){
          window.location=$(this).find("a").attr("href");
          return false;
          });
});
</script>
The script finds the link tag ".find .attr href" and places it as a click function for the li as a block.
Rob_Che is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:06 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com