how to get content of all
  • tags in one page using jquery
  • 后端 未结 3 1338
    借酒劲吻你
    借酒劲吻你 2021-01-24 04:43

    I have an html list something like this:

  • red
  • yellow
  • blue
  • <
    相关标签:
    3条回答
    • 2021-01-24 05:24
      var $tags = $("li").map(function(){
        return $(this).text();
      }).get().join(",");
      

      Here, have a fiddle: http://jsfiddle.net/KTted/2/

      0 讨论(0)
    • 2021-01-24 05:30

      You can use jQuery.map()

      Live Demo

      texts = $('li').map(function(){
        return $(this).text();
      }).get().join(',');
      
      0 讨论(0)
    • First, you should change your id="tag" to class="tag", as you can't have multiple elements with the same id.

      You can build an array of the values:

      var content = [];
      $("li").each(function (element) {
          content.push[$(element).text()];
      });
      

      Or as others have pointed out, you can use map:

      var content = $("li").map(function() {
          return $(this).text();
      }).get().join(",");
      
      0 讨论(0)
    提交回复
    热议问题