2 Replies - 2018 Views - Last Post: 11 March 2013 - 06:01 AM

#1 littledevils326  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-November 12

Append and remove an element

Posted 19 February 2013 - 09:58 AM

Not sure if I am in the right section for this. I am currently designing a web page using javascript, html and css. The page is a seat booking seat which allows the user to select and unselect seats. I have managed to get the page to display id of the seat when the user have selected a seat, but I am having problems trying to remove id from the display if user unselects the seat.

Below is the javascript code

   	$('.available, .unavailable, .selected').click(function(){
    		var ID = $(this).attr('class');
    		if (ID == 'n unavailable' || ID == 'p unavailable') {
    			alert ('Seat is already booked. Please select another seat.');
    		}
    		else if (ID == 'n selected' || ID == 'p selected') {
    			alert ('You have now unselected this seat.');
    			$(this).html('<img src = "free.gif"/>');
    			$(this).removeClass('selected').addClass('available');
    			y--;
    			$("#seats").html("Number of seats selected: " + y);
    			$("#list").remove($(this).attr('id'));
    		}
    		else {
    			alert ('You have now reserved this seat. You can unselect it by clicking the seat again.');
    			$(this).html('<img src = "selected.gif"/>');
    			$(this).removeClass('available').addClass('selected');
    			y++;
    			$("#seats").html("Number of seats selected: " + y);
    			$("#list").append($(this).attr('id') + "</br>");
    		}
    	});



Is This A Good Question/Topic? 0
  • +

Replies To: Append and remove an element

#2 SpAm101  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 54
  • Joined: 28-November 12

Re: Append and remove an element

Posted 11 March 2013 - 05:35 AM

Hi littledevils326

I would suggest using the JQuery function .hasClass() to make your life a bit easier :)/>

http://api.jquery.com/hasClass/

This post has been edited by SpAm101: 11 March 2013 - 05:35 AM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3738
  • View blog
  • Posts: 13,067
  • Joined: 12-December 12

Re: Append and remove an element

Posted 11 March 2013 - 06:01 AM

It is (very) confusing, also, to use the variable name ID for a class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1