search

Home  >  Q&A  >  body text

javascript - I would like to ask, after creating a new node in jquery, insert it and then add css style to this node, can it be written in one sentence?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
    <title>s</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }

        
    </style>
</head>
<body>
    <p class="main">
        <p>111</p>
        <p>222</p>
        <p>333</p>
        <p>444</p>
        <p>555</p>
    </p>

    <script>
    $(document).ready(function(){
        var t = $("<p>hello world!</p>");
        $(".main").append(t);
        $(".main p:last-child").css("color","red");
    })
    </script>
</body>
</html>

Excuse me, Master, can the jquery here be written in one sentence? . .

曾经蜡笔没有小新曾经蜡笔没有小新2835 days ago669

reply all(1)I'll reply

  • 三叔

    三叔2017-06-26 10:55:28

      $("<p>hello world!</p>").appendTo(".main").css("color","red");

    reply
    0
  • Cancelreply