Reputation: 1568
How can i collect the ids of clicked spans using jquery?
what i've tried
$('.move-up').click(function(){
if ($(this).prev())
$(this).parent().insertBefore($(this).parent().prev());
});
$('.move-down').click(function(){
if ($(this).next())
$(this).parent().insertAfter($(this).parent().next());
});
var ids
$('span[id^="text_"]').click(function() {
$(this).toggleClass("highlight");
ids += $('span[id^="text_"]');
alert(ids);
});
Upvotes: 0
Views: 78
Reputation: 4748
$('.move-up').click(function() {
var myParentSpan = $(this).parents('span');
var myParentSpanId = myParentSpan.attr('id');
var mySpanTextContent = myParentSpan.find('span[id^="text"]').html();
// Your code here.
});
Upvotes: 0
Reputation: 2647
try this
$('.move-up').click(function() {
var spanId = this.id;
});
Upvotes: 0
Reputation: 6860
Then, make an array for ids
clicked_ids = new Array();
$('span[id^="text_"]').click(function() {
$(this).toggleClass("highlight");
clicked_ids.push($(this).attr('id'));
alert(clicked_ids);
});
Upvotes: 1