Getting value from href using jQuery

I wonder if anyone can help with the jQuery problem I am facing.

I use the tooltips from the jQuery tool library to create a popup when the mouse over the hrefed image, which I want to use to trigger a call to change the contents in the DIV.

The links I use take 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 use to run the tooltip 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 tried the following function to grab the identifier (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, I think my regex is really to blame ...

Once I get var pageNum, I assume I can just pass it to .load as:

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

Many thanks

+3
2

-, / :

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

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

-, , :

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

// should be
.match(/venue\/([0-9]+).htm/)[1]; 
+5

tooltip, , ... . jQuery , , , hrefd, URL-. , , , , .

0

Source: https://habr.com/ru/post/1743197/


All Articles