0

I want to pass an ID to a function that turns it to a "flyout".

My base code is:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="target_anchor1" href="#" title="XXXXXXXXXX">test 1</a>

<script type="text/javascript">
  $(function() {
    $('#target_anchor1').flyout({
      title: '',
      content: function() {
        return document.getElementById('target_anchor1').title;
      },
      html: true,
      dismissible: true
    });
  });
</script>

I want to do this dynamically, so I tried a function. Function gets the parameter but does not create the flyout.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="target_anchor1" href="#" title="XXXXXXXXXX" onclick="anchorFlyout(this.id)">test 1</a>
<a id="target_anchor2" href="#" title="YYYYYYYYYY" onclick="anchorFlyout(this.id)">test 2</a>
<a id="target_anchor3" href="#" title="ZZZZZZZZZZ" onclick="anchorFlyout(this.id)">test 3</a>

<script type="text/javascript">
  function anchorFlyout(paramId) {
    alert(paramId);
    $('#' + paramId).flyout({
      title: '',
      content: function() {
        return document.getElementById(paramId).title;
      },
      html: true,
      dismissible: true
    });
  }
</script>

Code is taken from http://www.jqueryscript.net/demo/Simple-Customizable-Tooltip-Popover-Plugin-Flyout

Any idea?

4
  • your question makes very little sense Commented Mar 8, 2017 at 3:01
  • @Andrew what about now? Commented Mar 8, 2017 at 12:16
  • Are you sure "flyout" is a thing? Stack Exchange's error tells me it's not. Commented Mar 9, 2017 at 1:51
  • jqueryscript.net/tooltip/… Commented Mar 9, 2017 at 10:41

2 Answers 2

1

Do you just want to be able to pass an ID to a function that turns it to a "flyout"?

function createFlyout(elementID) {
    $("#"+elementID).flyout({
        title: '',      
        content: function() {
            return document.getElementById(elementID).title;
        },
        html: true,
        dismissible: true
    });
}

Or you could use a custom JQuery function...

$.fn.createFlyout = function() {

    this.flyout({
        title: '',      
        content: function() {
            return this.attr("title");
        },
        html: true,
        dismissible: true
    });

    return this;
}
$("#myDiv").createFlyout();
Sign up to request clarification or add additional context in comments.

4 Comments

I want to pass an ID to a function that turns it to a "flyout". I didn't know how to explain it, sorry. I tried first suggestion (being honest, didn't understand how to use second one you told me.) So, I edited the post. Hope it is more clear now.
The second function is a jQuery custom function, and you'd call it just like you would call flyout. Instead of doing $(element).flyout( ... ), you could just do $(element).createFlyout(); In regards to the first function not working, are you getting any errors in console?
Your first function has return document.getElementById('#'+paramId).title;. It should not have a #, as getElementById is a native JS function: return document.getElementById(paramId).title;
I updated the code. I deleted the #. Got no errors in console. Function gets the param (the alert inside the function works) but it seems it is not "entering" here --> $('#'+paramId).flyout({ ....
1

Just make a regular function and have jquery statements in it:

function anchorFlyout(paramId) {
    $("#" + paramId).flyout({
        title: '',      
        content: function() {
            return document.getElementById(paramId).title;
        },
        html: true,
        dismissible: true
    });
};
anchorFlyout("target_anchor1")

6 Comments

tried this, but does not create the flyout. I have edited the code.
Well, you need to call the function: anchorFlyout("target_anchor1")
@OldBunny2800 I did that, check out the code above. I edited it.
Are you sure you did? I don't see any function callings. Edit: edited answer to show what I mean
I call it this way from the link --> onclick="anchorFlyout(this.id)"
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.