Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting value from href using jQuery

I wonder if anyone can help with a jQuery problem I am having.

I am using the tooltips from the Jquery Tools library to create a popup window when mousing over an hrefed image, this I want to use to cusomise the call to change the content in the DIV.

The links I am using are in the form:

<a href="/venue/1313.htm" class="quickView"><img src="/images/site/quickView83.png" alt="Quick View" width="83" height="20" /></a>

The code I am using to trigger the tip is:

$(".quickView").live('mouseover', function()
    {
        if (!$(this).data('init'))
        {
            $(this).data('init', true);
            ajax_quickView(); 
            $(this).tooltip
            ({ 
                /* tooltip configuration goes here */ 
                tip: "#quickViewWindow",
                position: "right",
                offset: [0, -300], 
                effect: 'slide' 
            });
            $(this).trigger('mouseover'); 
        }  
    });

I have tried the following function to grab the ID (in the example above, 1313) from the link:

function ajax_quickView(){
        var pageNum = $("a.quickView").attr("href").match(/venue/([0-9]+)/).htm[1];
        $("#quickViewWindow").load("/quick-view/", function(){}) 
    }

However I think this is where it falls down, I think my regex is prob to blame...

Once I get the var pageNum I presume I can just pass it into the .load as:

$("#quickViewWindow").load("/quick-view/", {id : pageNum }, function(){})

Many thanks

like image 285
bateman_ap Avatar asked Sep 17 '26 19:09

bateman_ap


1 Answers

Firstly, you haven't correctly escaped the / character in your regex:

/venue/([0-9]+)/

// should be
/venue\/([0-9]+)/

Secondly, you haven't correctly ended your regex, the entire line has a few syntax errors:

.match(/venue/([0-9]+)/).htm[1];

// should be
.match(/venue\/([0-9]+).htm/)[1]; 
like image 192
JJ. Avatar answered Sep 19 '26 11:09

JJ.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!