rabotalius
rabotalius

Reputation: 1568

how to collect ids

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);
});

http://jsfiddle.net/7W7Jz/13/

Upvotes: 0

Views: 78

Answers (3)

Aiias
Aiias

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

IT ppl
IT ppl

Reputation: 2647

try this

$('.move-up').click(function() {
  var spanId = this.id;
});

Upvotes: 0

hsuk
hsuk

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

Related Questions