Javascript - Change html tag type

后端 未结 8 1146
说谎
说谎 2020-11-30 14:03

i have a question, can i replace html tag to another ?

But i don\'t want to make the content blank. like this:

content<         


        
8条回答
  •  萌比男神i
    2020-11-30 14:40

    It would be invalid HTML (div elements do not have a href attribute) and not act like a link anymore.

    However, you could emulate the behaviour using JavaScript:

    $('div').on('click', function() {
        location.href = $(this).attr('href');
    });
    

    But please do not do this. It breaks middle-mouse-clicks (for a new tab) for example.

提交回复
热议问题