Sean De La Rosa Sean De La Rosa - 15 days ago 5x
HTML Question

function rfrsh() not working when put on an external javascript file

my function "rfrsh()" is working when it is inside the html file but when i put it on an external javascript file, it is now working anymore. here is my code

/* JavaScript */

$(document).ready(function() {

function rfrsh() {
$("iframe").each(function() {
var src= $(this).attr('src');

<!-- HTML -->

<div id="circtraff" class="tab-pane active">
<ul class="nav nav-pills" id="circtraff_tabs">
<li><a href="#circtraff_realtime" data-toggle="tab" onClick="rfrsh()"><i class="glyphicon glyphicon-dashboard" aria-hidden="true"></i>&nbsp; Real-time Traffic</a></li>
<li><a href="#circtraff_last24" data-toggle="tab" onClick="rfrsh()"><i class="glyphicon glyphicon-time" aria-hidden="true"></i>&nbsp; Last 24 Hours</a></li>

all other js functions are working except for the refresh function.


It's because you're scoping the rfrsh function to be local to the $(document).ready() function. To make it available to your HTML onClick event, define it in the window namespace, like so:

window.rfrsh = function() { /* ... */ };