Swift: Using append method to add item

For an array list, we could also use append method to add an item to the end of the list.

var list = ["David", "Derek", "Dragon"];

print("Total no of members: \(list.count)\n");

list += ["Emily", "Evan"];
list.insert("Amy", atIndex:0);

var item:String;

for item in list {
    print(item);
}

list.append("Michelle")

print("\nNow the updated list is:")

for item in list {
    print(item);
}

swift

jQuery Selectors: Appending a li to an ul element

This entry is part 6 of 33 in the series jQuery Selectors

Using jQuery selector, we can append a <li> item to a <ul> list.

We can use the same selector ul.rock to append an item to the second list.

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>Lists</title>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
    <script>
        $(function () {
            $('ul.rock').append('<li>Tracy Chapman</li>');
        });
    </script>
</head>
<body>

<h4>British Pop</h4>
<ul>
    <li>Cold Play</li>
    <li>Depeche Mode</li>
    <li>Adele</li>
</ul>

<h4>American Rock</h4>
<ul class='rock'>
    <li>Linkin Park</li>
    <li>Nirvana</li>
    <li>Metalica</li>
</ul>

</body>
</html>

jQuery: 2 DOM manipulation examples

This entry is part 13 of 33 in the series jQuery Tutorial

We use 2 simple examples to illustrate DOM manipulation concepts.

.after()
Insert content, specified by the parameter, after each element in the set of matched elements.
<!doctype html>
<html>
<head>
    <title>after demo</title>
    <style>
        p {
            background: yellow;
        }
    </style>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
</head>
<body>

<p>I would like to say: </p>

<script>
    $('p').after('<b>Hello</b>');
</script>

</body>
</html>

Try The Code

From the example above, you could see that the Hello text is inserted after the <p> elements.

.append()
Insert content, specified by the parameter, to the end of each element in the set of matched elements.

Whereas, the text in the example below is inserted immediately after the elements using append.  This can also be called inline or in the same line insertion.

<!doctype html>
<html>
<head>
    <title>append demo</title>
    <style>
        p {
            background: yellow;
        }
    </style>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
</head>
<body>

<p>I would like to say: </p>

<script>
    $('p').append('<strong>Hello</strong>');
</script>

</body>
</html>
Try The Code