-1

i need to do array and then send in php file with help ajax. I have code:

$(function() {
    $('.photo-user-change').bind('click', function(){
        var hasclass = $(this).hasClass('active');
        if(hasclass == true) {
            $(this).removeClass('active');
        } else {
            $(this).addClass('active');
            var iwa = $('.active').attr('id');
            alert(iwa);
        }
    });
});

and html:

<ul>
  <li class="photo-user-change" id="1">1</li>
  <li class="photo-user-change" id="2">2</li>
  <li class="photo-user-change" id="3">3</li>
</ul>

When added class 'active' need introduce ID into an array and then sent this array in php file. ID maybe a few.

How do this? I need create multi selector. thanks.

1
  • 1
    You need to better define your problem. First, what purpose overall is the code serving? You have an event handler for the click event on all elements of class photo-user-change, but what are those elements? Links, photos, divs? When [users] click, what do they expect to do? What does the array need to store, multiple IDs? Commented Jun 15, 2011 at 14:42

1 Answer 1

2

Here's a quick way to get all elements with the class active and photo-user-change and create a comma separated list of their id attribute. This could easily be converted to JSON format - for your PHP web-service. You would place this right before you fire off the web service call.

var ids = $('.photo-user-change.active').map(function() {
    return this.id;
}).get().join(',');

alert(ids);

See it in action - http://jsfiddle.net/XSRUb/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.