8

I've been using this successfully in my template:

<span class="sharethis-text">
<p>More  Options</p>
</span>
<script src="http://w.sharethis.com/button/buttons.js"></script>
<script>
stLight.options({
publisher:'******0b-6eed-4740-81e7-aa3ee0bd9f85',
});
</script>

But now I want to call this function in this:

<More-sharebar><a href="#">More options</a></More-sharebar>

How is it possible to include the script properly?

Apologies if the answer is easy. I'm a complete beginner. I've been searching but I can't find how to do it.

Edit: Thanks for the answers so far, and I think now I have the function stLight.options( but I don't know how to include the external js file. Instead of editing the functions.php file, is it possible to simply include the script above in my HTML, but give it a name, and somehow call that name in the href? The other thing: the function as it original works triggers on hover. I'd like to retain that, if possible. Apologies for my ignorance.

6 Answers 6

13

Javascript supports following syntax :

<a href='javascript:alert('Hi')'>ClickMe</a>

This should solve your problem.

This is the reference Draft

Sign up to request clarification or add additional context in comments.

Comments

3

If you have in your file.js the:

function helloWorld(){...}

You call in the href with a event this function:

<a href="#" onClick="helloWorld()">More options</a>

Comments

2

In mark <a> define attrib:

    onclick="javascript:functionName();"

or

    onclick="return functionName(attribs)"

This should help.

But it should be done like this:

<a id="do_something">
   aaa
</a>

<script type="text/javascrip">
$.(function(){
   $('a#do_something').click(functionName());
});

1 Comment

The js file is external to my site, and the function won't work unless I combine it with the Publisher ID. So I'm having trouble knowing what function to call, or how to add my Publisher ID to the new code.
2

Just put this Javascript inside your href:

<a href="javascript:;">More options</a>

Comments

0

in the HREF, you'll call the function you need, not the script file itself.

So you have to include your script in your HTML file (if possible at the end of the file, not in the header) and then call the method/function from your href.

1 Comment

So I can strip the <span> class, and just need to know how to call the function. I'm just struggling to find the name of the function
0
  1. Write a function that calls the function you want. According to your post, maybe it's stLight.options? Return false if you don't want the navigating behavior of the a link.

    function clickHandler() {
        stLight.options({
            publisher:'******0b-6eed-4740-81e7-aa3ee0bd9f85',
        });
        return false;
    }
    
  2. Add the onclick handler to the a link.

    <More-sharebar><a href="#" onclick="javascript:clickHandler()">More options</a></More-sharebar>
    

2 Comments

Many thanks. How would I include w.sharethis.com/button/buttons.js in the function? It's an externally hosted file. And sorry for my ignorance, but the original function worked on hover, not click. Is there a onhover possibility for the href?
You can add <script src="http://w.sharethis.com/button/buttons.js"></script> in <head> or some other place in the html. The browser will download and include the external script file as soon as it sees that script tag. For hover action, checkout onmouseover and onmouseout. It's just like onclick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.