The attr() method returns a string, rather than the jQuery object, so you won't
be able to chain
it. You could modifiy the $.query function and pass in the value of q ... like
so:
jQuery.query = function(q) {
var r = {};
q = q.replace(/^\?/,''); // remove the leading ?
q = q.replace(/\&$/,''); // remove the trailing &
jQuery.each(q.split('&'), function(){
var key = this.split('=')[0];
var val = this.split('=')[1];
// convert floats
if(/^[0-9.]+$/.test(val))
val = parseFloat(val);
// ingnore empty values
if(val)
r[key] = val;
});
return r;
};
Then call it like this:
q = $.query($(this).attr('href'));
Luke
Chris W. Parker wrote:
> On Tuesday, October 31, 2006 10:46 AM Luke Lutman <> said:
>
>> Have a look at this recent thread :-)
>>
> http://www.nabble.com/method-plugin-for-getting-query-string-vars--tf248
> 1232.html#a6919130
>
> I read through this and tried to implement your first suggestion but I
> notice that everything takes location.search and parses that. I want to
> use it in the following way:
>
> theHref = $(this).attr("href").query();
>
> Your function is:
>
> jQuery.query = function() {
> var r = {};
> var q = location.search;
> q = q.replace(/^\?/,''); // remove the leading ?
> q = q.replace(/\&$/,''); // remove the trailing &
> jQuery.each(q.split('&'), function(){
> var key = this.split('=')[0];
> var val = this.split('=')[1];
> // convert floats
> if(/^[0-9.]+$/.test(val))
> val = parseFloat(val);
> // ingnore empty values
> if(val)
> r[key] = val;
> });
> return r;
> };
>
> I'm not sure how to modify that function to do what I want (considering
> my current lack of JS/jQuery syntax). Would you mind showing me what to
> do?
>
>
> Thank you,
> Chris.
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
--
zinc Roe Design
www.zincroe.com
(647) 477-6016
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/