Writing HTML with jQuery

前端 未结 3 1552
悲&欢浪女
悲&欢浪女 2021-01-06 00:45

I am new to jQuery. I want to write the following HTML (along with the classes) using jQuery. How can I do this?

相关标签:
3条回答
  • 2021-01-06 01:00

    Well you can just use append() or the other DOM Insertion Functions

    $(document.body).append('<div class="phnbr"><div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a></div></div>');
    
    0 讨论(0)
  • 2021-01-06 01:21
    $('<div class="phnbr"> \
      <div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a> \
      </div> \
    </div>'); // bang done!
    
    0 讨论(0)
  • 2021-01-06 01:22
    $('<div>').addClass('phnbr').append($('<div>').addClass('phtext').append('hi how are you, ').append($('<a>').attr({ target: '_blank', href: 'http://www.xyc.com'}).text('click here.')));
    
    0 讨论(0)
提交回复
热议问题