Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  90] [ 1]  / answers: 1 / hits: 31173  / 11 Years ago, tue, june 18, 2013, 12:00:00

I have a series of pages where I need to get a specific code for a button.
I want to put the code which is in the url into a variable with jQuery.



An example URL is www.example.com/folder/code/12345/



I want to get the number part in a variable called (siteCode)



Thanks in advance for any answers.



jquery / Pseudo code:



var siteCode;

// start function
function imageCode(){
siteCode // equals number part of URL
$('.button').attr('src', 'http:www.example.com/images/'+siteCode+'.jpg');
}

More From » jquery

 Answers
21
var str=url;

str.split(/)[3]


you can use split


[#77567] Monday, June 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
halleyb

Total Points: 604
Total Questions: 96
Total Answers: 115

Location: Tokelau
Member since Wed, Oct 14, 2020
4 Years ago
;