Skip to content

Instantly share code, notes, and snippets.

@beezly
Last active August 29, 2015 13:56
Show Gist options
  • Save beezly/9186841 to your computer and use it in GitHub Desktop.
Save beezly/9186841 to your computer and use it in GitHub Desktop.
Update or set a parameter in querystring found inside an element attribute (useful for changing the parameters to an <img src="blah?foo=true"> attribute)
setQueryStringParameter = (element, elementAttr, paramName, paramValue) ->
src=element.attr elementAttr
splitSrc=src.split '?'
uri=splitSrc[0]
qs=splitSrc[1]
qsObject={}
qs.split('&').forEach (attribute) ->
split_attr=attribute.split('=')
qsObject[split_attr[0]]=split_attr[1]
console.log qsObject
qsObject[paramName]=paramValue
qs=Object.keys(qsObject).map (key) -> key+'='+qsObject[key]
src=uri+'?'+qs.join('&')
element.attr elementAttr, src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment