Martin G.
Martin G.

Reputation: 13

How can i put variable into load function in jquery?

How can i put variable into "load" function ? - i need to recover source filename and put in location

function updateClock() {
    var loc = $(location).attr('pathname');
    // $("#clock").load('index.php #clock');  <- this one is working but I need variable 
    $("#clock").load('$loc #clock'); < -problem with $loc variable(how to implement)
}

$(document).ready(function() {
    setInterval('updateClock()', 1000);
});

Upvotes: 0

Views: 50

Answers (2)

tanaydin
tanaydin

Reputation: 5306

If you put your variable in string value like

$("#clock").load('$loc #clock');

interpreter thinks that as a string.. so put it outside and make it like...

$("#clock").load(loc + ' ' + '#clock');

that should work.

Upvotes: 1

Martin G.
Martin G.

Reputation: 13

With help from user "tanaydin", the solution is :

$("#clock").load(loc + ' ' + '#clock');

Upvotes: 0

Related Questions