how to call global function in jquery -


i have make 2 global function want call them in html page. have make separate file global function , calling them our html page seems wrong code

<script type="text/javascript"> (function ($) { jquery.functionone = function () { var text = "i first" }; jquery.functiontwo = function (param) { var text = "i second" }; })(jquery); $('.first').text().functionone(); $('.second').text().functiontwo(); </script> <body> <div class="first"></div> <div class="second"></div> </body> 

try please: if calling these functions within text function try code below: demo http://jsfiddle.net/smltp/ or http://jsfiddle.net/smltp/1/

update demo according updated code: http://jsfiddle.net/smltp/8/

if keen: http://api.jquery.com/text/

hope helps or please lemme know if missed anything! :)

$('.first').text(function(){ return functionone(); }); $('.second').text(function(){ return functiontwo(); }); 

sample function =>

 $('.first').text(function(){ return functionone(); }); function functionone(){ return "hulk awesome"; } รข€‹ 

update

functionone = function() { var text = "i first" return text; }; functiontwo = function() { var text = "i second" return text }; $('.first').text(function() { return functionone(); }); $('.second').text(function() { return functiontwo(); }); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -