scriptaculous Builder在jQuery中的等价物?

时间:2012-03-02 20:06:05

标签: jquery scriptaculous

我喜欢scriptaculous Builder语法来创建DOM元素。 在jQuery中有类似的东西吗?

我不想使用像

这样的东西
$("<div><p>Hello</p></div>").appendTo("body")

1 个答案:

答案 0 :(得分:2)

DOMBrew是一个选项http://jsperf.com/jquery-dom-vs-custom-dom/4

var $b = DOMBrew;

$("#thetable").append($b('tr#row-of-one').append(
  $b('td.red').append(
    $b('ul').append(
      $b('li.lists', 'one'),
      $b('li', 'two')
    )
  ),
  $b('td.blue').append(
    $b('p', 'This is a bunch of text that is right here.')
  ),

  $b('td.orange').append(
    $b('table#smallertable').append(
      $b('thead').append(
        $b('tr').append(
          $b('th', { colspan: 2, text: 'this is small' })
        )
      ),
      $b('tbody').append(
        $b('tr').append(
          $b('td', 'Go win.'),
          $b('td', 'Go fight.')
        )
      )
    )    
  ),

  $b('td.purple').append($b('#divided', 'Content'))
).dom());