SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    jquery add new element moves to top

    I have a small script which adds form input fields dynamically but whenever I click the button to add a new element the screen scrolls to top, is there a way to stop that?

    this is my script:

    Code JavaScript:
    var fundadores = 1;
    $('.fs_fundadores .agregar').click(function() {
    	fundadores ++;
    	$('<div class="clearfloats"><label>' + fundadores + '. Nombre</label><input class="field" type="text" value="" name="dynamicn[]"><label>Correo</label><input class="field" type="text" value="" name="dynamicem[]"></div>').fadeIn('slow').appendTo('.fs_fundadores');
    }); 
    $('.fs_fundadores .quitar').click(function() {
    if ( fundadores > 1 ) {
    	$('.fs_fundadores').children("div:last").fadeOut().remove();
    	fundadores --;
    }
    });
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  2. #2
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Never mind, I just realized that my anchor tags were the ones causing it, I added the .preventDefault(); to the function.
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •