Search code examples
javascriptjqueryhtmltooltip

Have some problems with my javascript


i have some problems with my script , i used JqueryUI tooltip but it doesn't work . Sample demo is given below.

http://jsfiddle.net/VFZL7/.

$(function() {
$("a[id*='product_wrap']").tooltip({
content: function(){return $(this).html().replace('150_','')},
track: true,
});
});

I want my tooltip indicates the image petplusvn.com/files/sanpham/16/150.jpg instead of petplusvn.com/files/sanpham/16/150_1.jpg.


Solution

  • You can use regular expressions to replace both URLs ( in src and data-original )

    $(function() {
    
        $("a[id*='product_wrap']").tooltip({
    
            content: function(){
                var $html = $(this).html().replace(/150_/g, '');
                console.log('new HTML: '+$html);
                return $html;
            },
        track: true,
    
        });
    });
    

    http://jsfiddle.net/7Y8Au/