Hello, I am new to jquery and programmering. I want to add an span container in my html document’s div container. The div that I want to append to on my html document looks this:
.
<script type="text/javascript">
var test = ['A', 'B'];
var counter = 0;
$(document).ready(function(counter){
$('#test').append('<span>' test[counter] '</span>');
-if/else here?
}
});
</script>
I need to check if I am at the end of my array, so if I am at 1 (‘B’), I would be at the end of the array, then reset the counter to 0, so I can loop my array, making the text change in the div, if that makes any sense… I am not the best at explaining, I’m sorry
why use a counter like you did? You can simple make a for loop:
result = "";
arrayLength = test.length;
for (var i = 0; i < arrayLength; i++){
result += '<span>' + test[counter] + '</span>';
}
$("#test").append(result);
Hmm, let me try to be more clear. The code above is in regular javascript, I know that it is just something I found, which does something close to what I want. The code loops through the array “var example = [‘A’, ‘B’, ‘C’, ‘D’];”. What I want to do is make use of jQuery, for making the them fadeIn and fadeOut as the div changes it’s content…