Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call js / script within href

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.

like image 863
Ian Douglas Avatar asked Mar 23 '13 08:03

Ian Douglas


4 Answers

Javascript supports following syntax :

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

This should solve your problem.

This is the reference Draft

like image 140
Nitin Jadhav Avatar answered Sep 20 '22 01:09

Nitin Jadhav


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());
});

like image 30
Mr.TK Avatar answered Sep 19 '22 01:09

Mr.TK


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>
like image 25
CGG Avatar answered Sep 20 '22 01:09

CGG


Just put this Javascript inside your href:

<a href="javascript:;">More options</a>
like image 45
Moode Osman Avatar answered Sep 22 '22 01:09

Moode Osman