Inkey
Inkey

Reputation: 2207

Jquery Add To List from text boxs

I have got the following list

<ul id="js-news" class="js-hidden">
    <li class="news-item"><a href="#">This is the 1st latest news item.</a></li>
    <li class="news-item"><a href="#">This is the 2nd latest news item.</a></li>
    <li class="news-item"><a href="#">This is the 3rd latest news item.</a></li>
    <li class="news-item"><a href="#">This is the 4th latest news item.</a></li>
</ul>

This runs via a news ticker that i found on-line How would i go about adding to the list using jquery from a text box with a add button.

Is it possible to add to this list from a a different page using jquery.

Upvotes: 0

Views: 131

Answers (3)

Rory McCrossan
Rory McCrossan

Reputation: 337580

To add extra items to your list, try this code:

$("#myButton").click(function() {
    var $li = $("<li></li>").addClass("news-item");
    var $a = $("<a></a>").attr("href", "#").text("This is the Nth item").appendTo($li);
    $li.appendTo("#js-news");
});

Note that you may need to re-initialise your news ticker component, depending on whether it reads the li element into an array on load, or is constantly referencing them to pick up additiions.

Upvotes: 2

Stefan Koenen
Stefan Koenen

Reputation: 2337

Because you want a news ticker, you also want other people can see it i think? :). So you need to create a new form in php or any other language you are using for the website and add a new news item in a database. On the page where you want to display this, just read the values from the database and create a list of them.

greets, stefan.

Upvotes: 0

user862010
user862010

Reputation:

You can do this only if is pop up window, and that needs to be opened by you site.

Upvotes: 0

Related Questions