Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:30:55+00:00 2026-06-16T17:30:55+00:00

I have this jQuery function: $(‘.scrollToLoginBox’).click(function(){ $(‘html, body’).animate({scrollTop: $("#LoginBox").offset().top-5}, ‘slow’); }); I don’t want

  • 0

I have this jQuery function:

$('.scrollToLoginBox').click(function(){
    $('html, body').animate({scrollTop: $("#LoginBox").offset().top-5}, 'slow');                
});

I don’t want it as a class, I’d like to be able to call it like this: onClick="scrollTo(id);"

So, how can I put the function in JavaScript format:

function scrollTo(id){
    $('html, body').animate({scrollTop: $("#'+id+'").offset().top-5}, 'slow');
}

EDITED by publisher:

I appreciate all your answers, but I’m not trying to get the id. On the other hand, I’m trying to build the same function I published above. So, that on a click I will send the id (which I have Example Login or LoginBox), so that the function will scroll slowly to the anchor (id=Login or LoginBox).

Now I have to call it like this: class="scrollToLoginBox", instead I’d like to call it onClick="scrollTo('LoginBox');.

I have 20 identical functions like the above, one for each id. Another example of what I have and I don’t want is: class="scrollToSettings", instead I’d like to call it onClick="scrollTo('LoginBox'); or onClick="scrollTo('Settings');

            $('.scrollToSettings').click(function(e){
        $('html, body').animate({scrollTop:$("#settings").offset().top-5}, 'slow');         
        return false;       
    });
    
    $('.scrollToFaqs').click(function(e){
        $('html, body').animate({scrollTop:$("#formCode").offset().top-5}, 'slow');         
        return false;       
    });

I would like only one function that takes the id. I just don’t know how to pass the id to this jQuery function ;o)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:30:57+00:00Added an answer on June 16, 2026 at 5:30 pm

    If you want to pass id to item being clicked, then you need to use this.id

    Live Demo

    onClick="scrollTo(this.id);"
    

    If you want to pass id of some other control then you simple pass the id as string.

    onClick="scrollTo('idOfHTMLElement');"
    

    Edit based on comments, for passing values from html elements to javascript function.

    Data attributes are used for hold custom attributes and could be
    accessed in jQuery function use data() function.

    Html

    <div class="scrollToCal" data-idtopass="Anchor">click me to go to Anchor</div>​
    

    Javascript

    jQuery(document).ready(function($) {
    
        $('.scrollToCal').click(function() {
    
            $('html, body').animate({
                scrollTop: $('#' + $(this).data('idtopass')).offset().top - 5
            }, 'slow');
            return false;
        });
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this jquery code $(#eioShowLink).on('click',function(){ $(#ioEditRelatedConcepts).html(''); $.getJSON(http://localhost/Mar7ba/Ontology/getRelatedConceptsAndRelations/+conceptName+/TRUE, function(data){ var concepts = data[0]; var
I have this jquery function: $(window).scroll(function () { if ($(window).scrollTop() > offset.top) { $(#sidebar).css(marginTop,
I have this code jQuery('.button').click(function() { jQuery('.div1').animate({width: 'toggle'}); jQuery('.div2').animate({width: '100%'}); }); Works fine for
I have this jQuery: $(document).ready(function() { $(#panel).hide(); $('.login').toggle( function() { $('#panel').animate({ height: 150, padding:20px
Suppose I have this jQuery code. $(document).delegate('a[title]', 'click', function(event) { var txt = //
I have this JQuery code: jQuery(#form).click(function() { $(input[name='copyno']:checked).each(function() { checkboxData = copyno=+$(this).val(); id=$(this).val(); jQuery.ajax({
I have this jQuery function: $('#invite_friends_email').live('click' , function() { $(#invite_friends_email).dialog(); return false; }); and
I have this: jQuery(document).ready(function(){ jQuery('a.color2030').click( function() { jQuery('tbody').hide(); jQuery('tbody.color2030').show(); }); jQuery('a.color2031').click( function() { jQuery('tbody').hide();
I have this interesting jQuery function. It basically adds a click handler to link,
I have this jQuery snippet: $(function() { $(ul > li).hover(function() { $(this).find(ul).stop(true, true).animate({opacity: 'toggle'},

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.