2

I have the folowing code that switches out a class on a div. I need something similar but with id. Is that done with get attribute? Not sure how this should be done but it should work the same as the code below in that a clicked link changes the ID..

$('#calendar-links a').click(function(e){
    e.preventDefault();
    var calendar_class = $(this).attr('data-class');
    $('#calendar-links a').removeClass('active');
    $(this).addClass('active');
    $('#aecp-calendar').removeClass('all current future events').addClass(calendar_class);
});
user3029697
  • 53
  • 1
  • 1
  • 8

2 Answers2

4
$('#calendar-links a').click(function(e){
    $("#myElement").attr("id", "newId");
});

Where newId is the "new" ID for your element.

FastTrack
  • 8,810
  • 14
  • 57
  • 78
1

The ID can be set like the following:

 $(this).attr('id','newID');
Trevor
  • 16,080
  • 9
  • 52
  • 83