开发者

Change links into anchor links on load with jQuery

开发者 https://www.devze.com 2023-02-08 02:04 出处:网络
I am trying to set up my webpage so that the HTML has normal links and then they change to anchor links on DOM ready.

I am trying to set up my webpage so that the HTML has normal links and then they change to anchor links on DOM ready.

So far i've had no luck, i'm still relatively new to using regular expressions so I have mos probably tried doing it all wrong.

Heres my jQuery code:

    $(".LINKS").each(function() {

        $(this).attr(
            "src",
            $(开发者_如何学Gothis).attr("src",replace('/\/\?page\=*?/ig', "/#"))
        );


    });

Any suggestions?


Links in html are done with an href attribute on the a node, not an src. src is for image url in img nodes.

$(".LINKS").each(function() {
    $(this).attr(
        "href",
        $(this).attr("href",replace('/\/\?page\=*?/ig', "/#"))
    );
});


Besides the other guys' comments about "href", you have specified a STRING rather than a REGULAR EXPRESSION:

replace('/\/\?page\=*?/ig', "/#")

should be:

replace(/\/\?page\=*?/ig, "/#")

i.e. get rid of the apostrophes surrounding the first argument.

0

精彩评论

暂无评论...
验证码 换一张
取 消