Im trying to extract the value of a single $_GET variable contained in a link.
So the html looks like:
<div class="news_item"><a href="http://example.com/?p=51">Title</a></div>
And I am trying to pull out just '51' from this url using JS:
<script>
function GetURLParameter(sParam, URL) {
var sURLVariables = URL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
};
$('.news_item a').click(function(e) {
e.preventDefault();
var URL = $(this).val('href');
var sParam = 'p';
var ID = GetURLParameter(sParam, URL);
alert(ID);
});
</script>
When I click on the link I get the following error: Uncaught TypeError: Object [object Object] has no method 'split'
Any ideas what is happening? I can't figure out what I have done wrong..