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 7536505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:35:35+00:00 2026-05-30T06:35:35+00:00

I asked this question regarding changing the position of a bootstrap popover depending on

  • 0

I asked this question regarding changing the position of a bootstrap popover depending on the size of the screen.

The answer was great – however I also now want to change the action for popovers (so it’s on click for mobile) as well as the location, and am having difficulty re-factoring the code. This is what I have:

$(document).ready(function(){
    $('#my_list li').popover({
        placement: wheretoplace
    });
});

function wheretoplace(){
    var width = window.innerWidth;
    if (width<500) return 'below';
    return 'left';
}

How would I amend the wheretoplace function to return two things: the placement value along with a trigger value? I’ve got the existing stuff in a jsFiddle.

Edit – I’ve amended my jsFiddle above to show the complete solution, adding a click event to @James’ answer below.

  • 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-05-30T06:35:36+00:00Added an answer on May 30, 2026 at 6:35 am

    If you are trying to return two values from the function, try assigning them as properties of an object and then return that object.

    eg.

    function wheretoplace(){
    
        var data = {};    
    
        var width = window.innerWidth;
    
        if (width<500)
        { 
            data.placement = 'below';
        }
        else
        {
            data.placement = 'left';
        }
    
        data.trigger = "myEvent";
    
        return data;
    
    }
    

    Then in the function calling wheretoplace:

    $(document).ready(function(){
        $('#my_list li').popover({
            placement: wheretoplace().placement,
            trigger: wheretoplace().trigger
        });
    });
    

    Is this what you are trying to do?

    EDIT: In Response to the comment below:

    As with the jsFiddle demo

    By assigning the trigger as “manual” on document ready, you are then able to call $(element).popover("toggle") in a click handler which will toggle the appearance of the popover.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question before and got a great working answer. what is the
I asked a question regarding Bi linear transformations and received this answer: From that
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
I recently asked this question regarding pulling beans out of an applicationContext. The answer
I previously asked a question regarding this , got an interesting answer which got
Yesterday, I asked this question regarding best practices for a simple information retrieval system
I asked this question before, Here however I think I presented the problem poorly,
I asked a question on Javascript this points to Window object regarding this points
I asked this question earlier but regarding another programming languages. Let's say I have
I asked this question regarding a strange behaviour from a GridView control in ASP.Net

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.