JavaScript - Regexp Uri Hash
Hey there, I'm looking to have some functionality similar to Twitter in that pages are loaded through ajax depending on the path that is shown in the URI hash.
For example: http://twitter.com/#!/BarackObama/following I could just split the string by "/" but I want it to work if you enter a bunch of forward slashes as well, or none at all (only for the first forward slash), here's an example: http://twitter.com/#///////////BarackObama/following http://twitter.com/#BarackObama/following http://twitter.com/#/BarackObama The hash would be broken down into multiple parts, the first parameter (ie. BarackObama) would be the first returned value from the match, the second would be the rest of the parameters. Here are examples of what the hash would be, and what I would like in return. Hash: 1. http://twitter.com/#/BarackObama/following/test 2. http://twitter.com/#///////////BarackObama/following 3. http://twitter.com/#BarackObama Returned value from RegExp match: 1. BarackObama,following/test 2. BarackObama,following 3. BarackObama Hope that makes it pretty clear. I also have this so far, but it returns both a comma separated list, but also the original string. Code: /([0-9A-z]+)\/?(.*)/ Similar TutorialsI am using in script http://www.vicsjavascripts.org.uk/Wo...ordToolTip.htm Code: for (;z0<wary.length;z0++){ reg=new RegExp('\\b'+wary[z0][0]+'\\b','g'); html=html.replace(reg,'<a>'+wary[z0][0]+'</a>'); } html=html.replace(/zxc/g,'<'); I expected to be able to use Code: for (;z0<wary.length;z0++){ reg=new RegExp('\\b'+wary[z0][0]+'\\b','gi'); html=html.replace(reg,'<a>$1</a>'); } html=html.replace(/zxc/g,'<'); where $1 = the replaced text can someone please explain? All, If I have the following URL: http://example.com/viewpage.php?id=test Then when I write a hash the URL goes to: http://example.com/viewpage.php?id=test#id=nexttest I have the following code: Code: function redirectHash() { var hash = location.hash; if (hash){ hash = hash.replace('#', ''); location.href = hash; } } </script> Currently this code would try and redirect me to http://example.com/id=nexttest How can I get it so that it keeps everything before the ? and just updates the id part? Thanks in advance. Hi all, I am having trouble understanding how to get RegExp to work. I've read so many tutorials but none have been clear. They all just explain the patterns you can check for but not how to piece them together! I am trying to write a RegExp pattern that checks an email address so that it allows the characters a-zA-z0-9_ before and after the @ How would I go about doing this? I tried Code: new RegExp("[a-zA-z0-9_].+@[a-zA-z0-9_].+"); but that didnt work. I appreciate any help Hello @all readers, i'm trying to extract some text out of an options-selectmenu. The text of these option menus are pulled out of a webdb. For each option there excist a main value,for each main value, there excist an aditional price,either a minus (-) or a plus (+) to the main price: main item: graphiccard price 200,- options: 16 Mb (- 10) 32 Mb (main price,no need to get aditional value) 64 Mb (+ 50) 128 Mb (+ 100) So if user choose 128 MB (+ 100) i require a var that say's : 128 MB a var that say's: + a var that say's : 100 All selected options could contain many variants, it isnt pinned to the sample above,however,all options are formatted like this: someTextAndMabyNumbers_1 (aPlusOrMinusSign_2 AlwaysaNumber_3) I would apreciate to get a solution to this problem. I am not programming for living,the end result is for community.(oscommerce) To see a live version , ask me for the url (incase of seen as spam i not post until aprovement) Here is the code i pull out from the selectmenu,all alternative methodes instead of using regexp are much welcome. Code when clicked submit button and the regexp result var comes: Code: $("#submitme").live('click', function() { var mystringId = prodID; var addedOn = new Date(); $('select').each(function() { var selectId= $(this).attr("id"); var selectedOption = $(this).find('option:selected'); var selectedOptionValue = selectedOption.val(); mystringId += '{' + selectId + '}' + selectedOptionValue; }); db.transaction(function(tx) { tx.executeSql('SELECT COUNT(*) AS total FROM customers_basket WHERE products_unique_id ="'+ mystringId +'"', [], function (tx, results) { total = results.rows.item(0)['total']; if (total == 0){ $('select').each(function() { var selectName= $(this).attr("name"); var selectId= $(this).attr("id"); var selectedOption = $(this).find('option:selected'); var selectedOptionValue = selectedOption.val(); var selectedOptionText = selectedOption.text(); db.transaction(function(tx) { tx.executeSql('INSERT INTO customers_basket_attributes (customers_id, products_id, products_unique_id, customers_basket_quantity, products_options_id, products_options_txt, products_options_value_id, products_options_value_txt) values ("1" , "'+prodID+'" , "'+mystringId+'" ,"1", "'+selectId+'" , "'+selectName+'" , "'+selectedOptionValue+'" , "'+selectedOptionText+'")'); }); }); db.transaction(function(tx) { tx.executeSql('INSERT INTO customers_basket (customers_id, products_id, products_unique_id, customers_basket_quantity, final_price, customers_basket_date_added) values ("1" , "'+prodID+'" , "'+mystringId+'" , "1" , "0" , "'+addedOn+'")'); }); }else{ tx.executeSql('UPDATE customers_basket SET customers_basket_quantity = customers_basket_quantity + 1 WHERE products_unique_id ="'+ mystringId +'"'); tx.executeSql('UPDATE customers_basket_attributes SET customers_basket_quantity = customers_basket_quantity + 1 WHERE products_unique_id ="'+ mystringId +'"'); } }); }); $('.ui-dialog').dialog('close'); }); Code where the option selectmenu is generated: option.text(val+ ' (' +prefix+ ' ' +price+ ') '); representing the required regexp / alternativecode Code: for(key in products_options_array) { var value=products_options_array[key]; prodOpId = value['products_options_id']; prodOpName = value['products_options_name']; prodOpValueId = value['products_options_values_id']; prodOpValueName = value['products_options_values_name']; prodOpValuePrice = value['options_values_price']; prodOpValuePrefix = value['price_prefix']; var arr = [ { optionname: prodOpName, optionvalue: prodOpValueName, optionnameid: prodOpId, optionvalueprice: prodOpValuePrice, optionvaluepriceprefix: prodOpValuePrefix, } ]; for (var i = 0; i < arr.length; i++) { var r = arr[i]; //console.log(r); name = r.optionname; val = r.optionvalue; nameid = r.optionnameid; valueid = r.optionvalueid; price = r.optionvalueprice; prefix = r.optionvaluepriceprefix; if ($("#prodAttributes_"+prodID+" select").is("[name*=" + name + "]")) { var select = $("#prodAttributes_"+prodID).find("select[name*=" + name + "]"); var option = $("<option>"); option.val(valueid); if (price == 0){ option.text(val); }else{ option.text(val+ ' (' +prefix+ ' ' +price+ ') '); } select.append(option); } else { var select = $("<select>"); select.attr("name", name); select.attr("id", nameid); var option = $("<option>"); option.val(valueid); if (price == 0){ option.text(val); }else{ option.text(val+ ' (' +prefix+ ' ' +price+ ') '); } select.append(option); var label = $("<label>"); label.attr("class", "select"); label.attr("for", name); label.text(name); fieldset.append(select); myform.append(div); $(myform).appendTo("#prodAttributes_"+prodID); } } } myform.append(myinput); myform.trigger('create'); Thank you verry much!!!!!!!!! I would like to perform a regular expression on a string and if TRUE do something. I have huge amounts of knowledge doing this in PHP but trying out javascript. Much appreciated. I was wondering if anyone could help me with regexp: 1)I would like it so that both a first and last name can be entered and that both ' and - can be included 2)I would like it so that addresses have to start with a number and then each word afterwards has to start with a capital letter and can include full stops, ' and - Any help is appreciated! Hello, I have a the following text that I got from a getElementById and innerHTML and I need to get the model name from this text. Code: <div class="widgetWrap"> <div class="group1"> <h3><span>2010 Ford Escape XLT</span></h3> <dl id="vPrice"> <dt>2010 Ford Escape XLT Prices</dt> The last line has the year make model and trim level, I need to be able to get the model, "Escape" from here. The problem is the model does change, and I need to get whatever the model says, Focus, Expedition and so on. The make may change also, Lincoln or Mercury. Is there an easy way to get just the model name whatever it may be? I have been working on this for a while, and just can't get it. Thanks for your help Marc Damon I have project for long time now and cant seem to figure out how this work, this JS supposed to generate hash for the registration form, but how does it get values from the form? Form has onSubmit="return( onPreCreateAccountSubmit() );" ---------------------------------------------------------- function onPreCreateAccountSubmit() { doKtSubmit() ; return onPreCreateAccount(); } ---------------------------------------------------------- function doKtSubmit() { var ktlk = 'ktl'; var ktfk = 'ktf'; if (document.forms['createaccount'] && document.forms['createaccount'].elements[ktlk] && document.forms['createaccount'].elements[ktfk]) { KT_preSubmit() ; } return true; } PHP Code: <script type="text/javascript"> var KT_keydownHandler, KT_keypressHandler, KT_logEncoder, KT_lastElement = -1, KT_lastKeyCode = -1, KT_lastModifiers = -1, KT_logElement = 0, KT_stoppedLog, KT_ALLOW_FIELD_TYPES = { password: 1, text: 1 }, KT_ALLOW_FIELD_IDS = { firstname: 1, lastname: 1, email: 1, passwd: 1, passwdagain: 1, identityanswer: 1, secondaryemail: 1, newaccountcaptcha: 1, nickname: 1 }, KT_lastTime, KT_inputs, KT_keyInputs = []; if (window.captureEvents) { Event.KEYPRESS && window.captureEvents(Event.KEYPRESS); Event.KEYDOWN && window.captureEvents(Event.KEYDOWN) } function KT_preSubmit() { if (KT_logEncoder) { if (KT_keydownHandler) { KT_encode(16); KT_initHandlers(KT_inputs) } var a = KT_logEncoder; if (a.d != 0) { EN_encodeGroup(a, a.p); a.p = 0 } } } function KT_encode(a) { a < 0 ? KT_stopLog() : EN_encode(KT_logEncoder, a) } function KT_init(a, c, d) { a = KT_logElement = a; if (!a.value) a.value = "A"; KT_logEncoder = { e: a, p: 0, d: 0 }; KT_initHandlers(d); c = c; if (!c.value) for (d = 1; d < KT_keyInputs.length; d++) c.value += KT_keyInputs[d].name + " " } function KT_event(a, c) { if (KT_logElement.value.length > 3E3) { KT_encode(17); KT_stopLog() } else { var d; d = (new Date).getTime(); var b = d - KT_lastTime; KT_lastTime = d; d = b; b = a.k; var e = a.t, f = a.m; if (!(a.m & 3)) { c |= 2; if (b >= 65 && b <= 90) b = 65; else if (b >= 48 && b <= 57) b = 48; else if (c & 1) if (b >= 97 && b <= 122) b = 65; else if (b == 197 || b == 229) c &= 5; else if (b >= 192 && b <= 687) b = 192; else if (b >= 1536) b = 1536; else if (b >= 912) b = 912; else if (b >= 160) b = 160; else if (b >= 127) c &= 5; else if (b >= 33) b = 59; else c &= 5; else if (b < 48) c &= 5; else if (b < 65) b = 59; else if (b < 96) c &= 5; else if (b < 112) b = 96; else if (b < 187) c &= 5; else b = 59 } if (e != KT_lastElement) { KT_encode(c | 4); KT_encode(e); KT_lastElement = e } else { if (b == KT_lastKeyCode && f == KT_lastModifiers) { KT_encode(c | 8); KT_encode(d); return } KT_lastKeyCode = b; KT_lastModifiers = f; KT_encode(c) } KT_encode(b); KT_encode(f); KT_encode(d) } } function KT_initHandlers(a) { KT_keydownHandler = 0; KT_inputs = a; KT_stoppedLog = 0; var c = 1; for (a = 0; a < KT_inputs.length; a++) { var d = KT_inputs[a]; if (!(!KT_ALLOW_FIELD_TYPES[d.type] || d.id && !KT_ALLOW_FIELD_IDS[d.id.toLowerCase()] || d.offsetHeight == 0)) { d.onkeydown = KT_initKeyHandler; KT_keyInputs[c] = d; d.setAttribute("n", c++) } } } function KT_stopLog() { if (KT_keyInputs) for (var a = 1; a < KT_keyInputs.length; a++) { KT_keyInputs[a].onkeydown = 0; KT_keyInputs[a].onkeypress = 0 } KT_stoppedLog = 1 } function KT_getEventModel(a) { if (!a) { a = window.event; if (typeof a.keyCode == "number") return 1; return 0 } if (typeof a.which == "number") return 3; if (typeof a.keyCode == "number") return 2; if (typeof a.charCode == "number") return 4; return 0 } function KT_initKeyHandler(a) { var c, d = KT_logElement.value.length, b = ""; c = KT_getEventModel(a); switch (c) { case 1: a = window.event; b += "f=window.event;var b=f.keyCode;"; break; case 3: b += "var b=f.which;"; break; case 2: b += "var b=f.keyCode;"; break; case 4: b += "var b=f.charCode;" } KT_keypressHandler = 0; if (c != 0) { if (typeof a.modifiers == "number") b += "var c=f.modifiers;"; else if (typeof a.shiftKey == "boolean") b += "var c=f.shiftKey*4+f.ctrlKey*2+f.altKey;"; else KT_stopLog(); if (a.srcElement) b += "var d=f.srcElement;"; else if (a.target) b += "var d=f.target;"; else KT_stopLog() } else KT_stopLog(); if (!KT_stoppedLog) { b += 'var e=0;if(d.getAttribute("n")){e=d.getAttribute("n")}KT_event({k:b, m:c, t:e},'; KT_keydownHandler = new Function("f", b + "0)"); KT_keypressHandler = new Function("f", b + "1)"); KT_lastTime = (new Date).getTime(); KT_encode(0); KT_encode(KT_lastTime); if (d <= 1) { KT_encode(c); KT_encode(KT_keyInputs.length - 1) } } for (c = 1; c < KT_keyInputs.length; c++) { d = KT_keyInputs[c]; if (KT_keydownHandler) { d.onkeydown = KT_keydownHandler; d.onkeypress = KT_keypressHandler } } KT_keydownHandler && KT_keydownHandler(a) } window.KT_init = KT_init; window.KT_preSubmit = KT_preSubmit; this.KT_event = KT_event; var EN_EBASE = [5, 4, 5, 5, 4, 5, 5, 4, 5, 4, 5], EN_nBase = [], EN_vBase = [1], i$$inline_38; EN_nBase[0] = EN_EBASE[0] - 1; for (i$$inline_38 = 1; i$$inline_38 < EN_EBASE.length; i$$inline_38++) { EN_nBase[i$$inline_38] = EN_EBASE[i$$inline_38] - 1; EN_vBase[i$$inline_38] = EN_vBase[i$$inline_38 - 1] * EN_EBASE[i$$inline_38 - 1] } function EN_encodeGroup(a, c) { var d; for (d = 0; d < 4; d++) { var b = c % 67; a.e.value += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 *-._".charAt(b); c = (c - b) / 67 } a.d = 0 } function EN_encode(a, c) { function d(g) { b += g * EN_vBase[a.d++]; if (a.d >= EN_EBASE.length) { EN_encodeGroup(a, b); b = 0 } } for (var b = a.p, e = EN_nBase[a.d]; c > 0;) { var f = c % e; c = (c - f) / e; d(f); e = EN_nBase[a.d] } d(e); a.p = b; return a }; </script> Theres also this function function doKtInit() { var ktlk = 'ktl'; var ktfk = 'ktf'; if (document.forms['createaccount'] && document.forms['createaccount'].elements[ktlk] && document.forms['createaccount'].elements[ktfk]) { KT_init(document.forms['createaccount'].elements[ktlk], document.forms['createaccount'].elements[ktfk], document.forms['createaccount'].elements); } return true; } I have this string: this is my test <a href="yay.html">yay</a> and want to just match the part before the <a...: this is my test I can't figure out the regular expression for this. I've tried everything I can think of. It seems that it needs to do a non-greedy search on the first < it finds, but nothing works, like: ((.*<)?) Please help, thanks! hello all I am working on a keyword filter and am stuck on something that I am hoping someone has more experience with my problem is that I am trying to pass a regular expression as a variable to the RegExp() function in javascript but it does not seem to be working example below Code: var X = '^(?=.*?('; var Y = 'dog))(?=.*?(cat))(?=.*?(mouse'; // this gets created dynamically var Z = ')).*$'; var A = X + Y + Z; // result is ^(?=.*?(dog))(?=.*?(cat))(?=.*?(mouse)).*$ and is a valid and tested expression var B = new RegExp(A, 'i'); I want to pass B to a search() function but it does not seem to be accepted as a valid expression anymore thanks for any help Hello there I'm trying to build a simple little bot that you can ask questions. I'm using the indexOf method but I'm not sure if this is the best option for what I'm trying to do. If you type 'hello' or 'how are you' it answers. Any other input results in 'Dreadfully sorry but I didn't catch that. Say again?'. Is there a way that I can search input for certain words or combinations of words and trigger a single answer? Any help appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Bot</title> <script type="text/javascript"> function bot(go){var a = go.getElementsByTagName('input');var q = a[0];var t = q.value.toLowerCase();document.go.reset();if(t.indexOf('hello')!=-1){document.getElementById('bot').innerHTML = "Hello to you.";return false;}if(t.indexOf('how are you')!=-1){document.getElementById('bot').innerHTML = "I am functioning within acceptable parameters, thank you.";return false;};go.action=document.getElementById('bot').innerHTML = "Dreadfully sorry but I didn't catch that. Say again?"; return false;}; </SCRIPT> </head> <body onLoad="document.go.q.focus()"> <div align="center"> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <form name="go" onsubmit='return bot(go)' id="go" action=""><input name='q' type='text' /><input name='' type='hidden' /></form> <p> </p><div id="bot" align="center"></div> </div> </body> I have a situation where there is a string: m0|18:+:m1|(-3) which is a tracking method for preserving memory references in the following string: 18+(-3) In the user interface of the project I am working on; the user changes the string to: (18+(-3))*8 The object is to revise the memory tracking string to repersent the changes. should be: (m0|18+m1|(-3))*8 Code: //matches = this.getMemVals() // getMemVals() searches the string 'm0|18:+:m1|(-3)' // with regex pattern to find instances of m#|# var matches = new Array() matches[0] = 'm0|18'; matches[1] = 'm1|(-3)'; var currentStateSaved = '(18+(-3))*8'; var glbs = ''; for(i = 0; i < matches.length; i++) { var matRegex = new RegExp(matches[i].substring(matches[i].indexOf('|')+1), 'g'); alert('matReg: '+matRegex); glbs = currentStateSaved.replace(matRegex, matches[i]); } alert('GLBS: '+glbs) // <<< test code The '18' part of m0|18 is not be found in the revised literal string Why? (Has '18' been coverted to a number datatype?) This is the type of problem that drives me up a wall and cost far to much time trying to flush it out Thanks of suggestions, advice JK Code: <html> <head> <script> function testemail(){ var fld= document.getElementById("input1").value; var reg = /^[\w+]@[\w+].com$/i; if(reg.test(fld)) { alert("email is ok"); } else { alert("email is not correct"); } } </script> </head> <body> <p> <form name="form1" onsubmit="testemail()"> enter email : <input id="input1" type="text" /> <input id="input2" type="submit" value="Submit" /> </form> </p> </body> </html> I am trying to test an email ID with above RegExp. I enter a correct email or not, I am always getting message "email is not correct" So RegExp is not working. How can I find out whats wrong with this RegExp ? Is there any tool to figure that out ? I tried with FireBug, but it does not point to whats wrong with RegExp Thanks I have been testing regex test string to match the following pattern (- <any number with/without . decimal point>) ( -[#[.#]] ) here is the code that works the best: Code: var testStr = '99999+((-25.533) - 5)/99*(-25.533)'; var negValTestStr = new RegExp('\\(\-{1}[0-9]*\.?[0-9]*\\)', 'g'); var test = testStr.match(negValTestStr) alert(test); The question is: Why does it only work when the open and close parenthesis are double escaped: '\\(' and '\\)' When I use one backslash to escape, it will find -25.533, -5 and -25.533 With two backslashes for escape sequence: (-25.533), (-25.533) Also, I have to escape the - to get just one -. If I do not escape the -, -?; which should read - {0, 1} will match --# without escaping - Thanks for thoughts on this JK Hi all, I am having some troule with searching a string taken from a text field (a name textfield, it's basically a form and the script is validating it). I've been on the W3C schools website and I cannot get it to work, even with the "try it" feature. Please help. Code: function nameValidator(entry, msg) { var regExp = new RegExp("[a-z ]", "g"); var s_regExp = new RegExp("[ ]"); var tub = entry.value; var newLength = parseInt(tub.length); var i = 0; var space = 0; if (tub == "" || newLength > 20) { alert(msg + "entry must be > 1 and < 20 characters only!"); return false; } else if (tub.match(regExp)) { for (i=0; i < newLength; i++) { if (tub.substr(i,1) == "") { space += 1; } } if (space < 1) { alert(popup + "you must enter a space.") return false; } if (space > 1) { alert(msg + "you cannot enter a space more than once."); return false; } if (tub.substr(0,1) == s_regExp || tub.substr(newLength,1) == s_regExp) { alert(popup + "the first and last characters cannot be whitespace."); return false; } } return true; } 1. Specifically, it will not correctly evaluate the statement where I've used the s_regExp variable nor will it detect white space at the space counter so it never increases (which the rest of the code relies on!). 2. What am I doing wrong. W3C states just also to use var newvar = new RegExp("\s") but that doesn't work, and I have even tried var newvar = new RegExp("^([a-z ])*$", "g") and that's useless too. how about getting the attributes of the a tag? href and title and the innerhtml (actually the innerhtml has space on both ends)
Hey guys, What is wrong with the following regular expression: Code: <script language="javascript" type="text/javascript"> document.write('\\Green Apple\\u003c\\\/a>'.match(/(.*)\\\\u003c\\\\\\\/a>/)); </script> The ouput is: null I am escaping each backlash but it doesnt seem to be working... I am trying to get an alert when user type a digit in my textbox and i made this code: <script type=text/javascript> <!-- function allowed(){ var str=document.getElementById('firstname').value; var patt=/[0-9]/g; if(patt.test(str)){alert(not allowed);}; } //--> </script> <body> <input type=text id=firstname /> <input type=button value=Submit onclick="allowed();" /> </body> But when i click the button then nothing happen. Please help me. Thanks. Code: <html> <head> <script> function dt(){ var dt = new Date(); document.getElementById("time").innerHTML=dt; } function changeBgColor1(){ document.getElementById("bgc").style.backgroundColor='#ee0000'; } function changeBgColor2(){ document.getElementById("bgc").style.backgroundColor='#880099'; } function changeBgColor3(){ document.getElementById("bgc").style.backgroundColor='#888888'; } function validate(){ var a = document.getElementById("input1").value; var b = /[abcdef]/; if(b.test(a)){ return true; } else { alert("invalid character"); } } </script> <style> #bgc{ width:300px; height:100px; background-color:#cccccc; font-weight:bold; color:#ff00ff; } #time{ width:300px; height:50px; background-color:#aabb00; } </style> </head> <body onload="dt()"> <p id="time"> </p> <p id="bgc" onmouseover="changeBgColor1()" onmouseout="changeBgColor2()" onclick="changeBgColor3()"> Hi There, pls change bg color </p> <form id="form1" onsubmit="validate()"> <input id="input1" type=text /> <input id="input2" type="submit" value="Submit" /> </form> </body> </html> validate function does not work with IE or Firefox, it always returns true, even if some digits are entered in input box (which should not be validated by regexp). Why does regexp not work ? How to make it work ? Thanks Hi All I'm using the fantastic turtorial here for my site navigation: http://css-tricks.com/6336-dynamic-p...acing-content/ It's all working wonderfully but I've hit a major stubmling block. After the new page is loaded it won't load an scripts. E.g. I'm using scripts for expanding divs, galleries, contact forms etc and they simply don't run after the page transition Let me know if you need a link to my project I'm aware the page isn't actually 'refreshed' so I'm asuming they wont fire the standard way by having the script tags in the header (Please correct me if I'm wrong) So my question is how can I get them working once the new page is loaded? Script below: Code: $(function() { var newHash = "", $mainContent = $("#right"), $pageWrap = $("#wrap"), baseHeight = 0, $el; $pageWrap.height($pageWrap.height()); baseHeight = $pageWrap.height() - $pageWrap.height(); $("nav").delegate("a", "click", function() { window.location.hash = $(this).attr("href"); return false; }); $(window).bind('hashchange', function(){ newHash = window.location.hash.substring(1); if (newHash) { $mainContent .find("#guts") .fadeOut(200, function() { $mainContent.hide().load(newHash + " #guts", function() { $mainContent.fadeIn(200, function() { $pageWrap.animate({ height: baseHeight + $mainContent.height() + "px" }); }); $("nav a").removeClass("current"); $("nav a[href="+newHash+"]").addClass("current"); }); }); }; }); $(window).trigger('hashchange'); }); All help is appreciated Thanks in advance Craig |