waseem, why would you make this so complicated for someone just learning jquery?

OP didn't provide any info on where messages are coming from. Creating arrays, click counts etc when you don't have enough information to set anything up is very likely going to confuse someone. A couple of simple questions would  be far more appropriate

Suppose these messages are already in a file and all that is needed is $("#messageDiv").load("messageFile.html"); How would your solution help out?

perhaps OP is looking for guidance on how to get these messages to the page. Writing a bunch of long winded code based completely on assumptions doesn't help anyone, especially if it doesn't suit the need of situation.

Good starting point would be:

What is source of 4 messages? (already in page, external file, database etc)

if already in page > provide dom manipulation guidance
if in external file > provide .load() guidance
if in db or other source > provide appropriate guidance


waseem sabjee wrote:
I assume you with this done on an on click event


use the following html to test

<div id="object">
<div>
<a class="displaymsg" href="">Display Message</a>
</div>
</div>


the script for the following html

<script type="text/_javascript_">

$(function() {
// wait for DOM to FULLY load

// declare the div with id="object" as our refference point
var obj = $("#object");
//get the refference to the element we want to click
var displaymsg = $("a.displaymsg", obj);
// create our messages to test
var toDIsplay = [];
toDisplay.clickCount = 0;
toDisplay.message = new Array();
toDisplay.message[0] = "Hi";
toDisplay.message[1] = "Hello";
toDisplay.message[2] = "bye";

// create the click event of the object
/*
i made this special
i display message relevant to the elements click count
if you want to display all the messages you could use a for loop :)
*/
displaymsg.click(function(e) {
e.preventDefault() // similar to return false
obj.append(toDisplay.message[toDisplay.clickCount]);
toDisplay.clickCount++;
});

});

</script>
On Mon, Jun 22, 2009 at 4:07 PM, ryan.j <ryan.joyce.uk@googlemail.com> wrote:

have a look at .append() and .appendTo() ( http://docs.jquery.com/Manipulation/append
and http://docs.jquery.com/Manipulation/appendTo )

append will add some content to the end of an element, append to will
append a specified element to another.

if that's all g(r)eek to you, here is a brief description. if you had
an element with the class 'el' and the content 'test test test' and
ran the following snipped of script against it...

$(".el").append("RYAN LIKES TO APPEND");

...your element.el would now say 'test test testRYAN LIKES TO APPEND'.
the additional text would also be appended to any other elements with
that class in the document. use an id for a unique instance.








On Jun 22, 2:34 pm, anjith <anjithkumar.garap...@gmail.com> wrote:
> i need to display 4 messages(in news sectiiion) one after another in a
> div tag.....as in yahooo.....


Reply via email to