+ Reply to Thread
Results 1 to 2 of 2

Thread: jquery script

  1. #1
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    jquery script

    I am trying to make a script with jquery. The function is to add an additional <li> to an <ul>
    I have lots of <ul>'s, and i want to target a specific one. How is the best way to do this?

    I have this (simpliefied) html. The target <ul> is the one coming right after the "links" div
    Code:
    <div class="clear">
    	<div class="links">
    		<button type="button" class="makecomment">Comment</button>
    	</div>
    	<ul>
    		<li class="arrow">&nbsp;</li>
    		<li class="comment"></li>
    	</ul>
    </div>
    ... and that a couple o'times
    and this code :
    Code:
    $('button.makecomment').click(function(){
    	$('<li class="comment"></li>').hide().appendTo('').fadeIn('slow');
    });

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: jquery script

    It depends on the best way to relate the button to the list. If you're generating the HTML, you could use an ID selector. Alternatively, if the button and the list have the same relative position in the document structure, you could traverse the document:

    Code:
    $('.makecomment').live('click', 
        function (evt) {
            var comments = $(this).closest('.links').nextAll('ul').first();
            ...
        });
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. jquery UI & jQuery
    By droctoganapus86 in forum Programming Help
    Replies: 4
    Last Post: 06-27-2011, 09:33 PM
  2. jQuery .each()
    By pratham.gharat200395 in forum Programming Help
    Replies: 7
    Last Post: 02-10-2011, 08:12 AM
  3. jquery help
    By bioshock in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 10-28-2010, 08:47 AM
  4. jQuery & CSS Help...
    By toddart65 in forum Programming Help
    Replies: 7
    Last Post: 05-16-2010, 10:09 PM
  5. Javascripting/CSS not working - jQuery script
    By lachacar in forum Free Hosting
    Replies: 3
    Last Post: 05-11-2010, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers