Click here to Skip to main content
15,890,512 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Javascript HEX game Pin
Richard MacCutchan30-Apr-18 23:05
mveRichard MacCutchan30-Apr-18 23:05 
AnswerRe: Javascript HEX game Pin
Richard MacCutchan30-Apr-18 23:04
mveRichard MacCutchan30-Apr-18 23:04 
QuestionJavaScript beginner books, wich one? Pin
Member 1378482717-Apr-18 12:38
Member 1378482717-Apr-18 12:38 
SuggestionRe: JavaScript beginner books, wich one? Pin
Blikkies18-Apr-18 0:09
professionalBlikkies18-Apr-18 0:09 
AnswerRe: JavaScript beginner books, wich one? Pin
W Balboos, GHB4-May-18 7:15
W Balboos, GHB4-May-18 7:15 
QuestionJavascript on mobile application Pin
Member 1378151915-Apr-18 22:24
Member 1378151915-Apr-18 22:24 
QuestionMaking two cards match and then disappear with JQuerry Pin
Member 137670576-Apr-18 23:09
Member 137670576-Apr-18 23:09 
AnswerRe: Making two cards match and then disappear with JQuerry Pin
Christian75739-Apr-18 15:47
Christian75739-Apr-18 15:47 
I'm not sure what you're doing with the images, but I would do this:
Set an attribute on each of your .card elements perhaps called matchNum. (If you have to set this via jQuery you can use the .attr() function)

Then I would use something like this:
JavaScript
var otherSelectedCard = null; //Place to store a clicked-on card
$(".deck").on("click", ".card", function() {
  
  //If the user clicked the same card twice, "unselect" the card
  if (otherSelectedCard === this) {
    $(this).find("img").hide();
    otherSelectedCard = null;
    return;
  }

  //Check to see if a card is already selected
  if (otherSelectedCard !== null) {
    //One is, check if their a match
    if ($(otherSelectedCard).attr("matchNum").toString() === $(this).attr("matchNum").toString()) {
      //They are, make both cards disapear
      $(this).hide();
      $(otherSelectedCard).hide();
      otherSelectedCard = null;
    }
    else { //They're not, show the image, then hide both images
      $(this).find("img").show();
      var thisVar = this, otherSelectedCard2 = otherSelectedCard;
      setTimeout(function() {
        $(thisVar).find("img").hide();
        $(otherSelectedCard2).find("img").hide();
      }, 500);
      otherSelectedCard = null;
    }
  }
  else { //No card is selected yet, select the current one
    $(this).find("img").show();
    otherSelectedCard = this;
  }

});


This is my first time writing jQuery in a while so I probably goofed up somewhere in there. Hope this gives you a general idea of a solution here though Smile | :)
QuestionNewbie: how do I analyse DOM Objects? Pin
enginestar5-Apr-18 3:05
enginestar5-Apr-18 3:05 
AnswerRe: Newbie: how do I analyse DOM Objects? Pin
Richard MacCutchan5-Apr-18 4:34
mveRichard MacCutchan5-Apr-18 4:34 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
enginestar5-Apr-18 4:50
enginestar5-Apr-18 4:50 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
Richard MacCutchan5-Apr-18 6:10
mveRichard MacCutchan5-Apr-18 6:10 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
enginestar5-Apr-18 6:57
enginestar5-Apr-18 6:57 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
Richard MacCutchan5-Apr-18 7:00
mveRichard MacCutchan5-Apr-18 7:00 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
Christian75739-Apr-18 15:51
Christian75739-Apr-18 15:51 
QuestionisAuthenticated() always returns false irrespective whether user is logged in or not Pin
Member 137573661-Apr-18 22:55
Member 137573661-Apr-18 22:55 
QuestionHow do i create an apps using android studio? Pin
Siti nasuha28-Mar-18 16:12
Siti nasuha28-Mar-18 16:12 
QuestionSetting a variable to a string..Do.. While loop Pin
esljustin26-Mar-18 14:15
esljustin26-Mar-18 14:15 
AnswerRe: Setting a variable to a string..Do.. While loop Pin
Richard MacCutchan26-Mar-18 22:15
mveRichard MacCutchan26-Mar-18 22:15 
AnswerRe: Setting a variable to a string..Do.. While loop Pin
Weavr8-Apr-18 0:39
Weavr8-Apr-18 0:39 
Questionany shortcut to toggle in and out the jquery code Pin
indian14323-Mar-18 8:43
indian14323-Mar-18 8:43 
QuestionText to Image Font Size Pin
Member 1374210822-Mar-18 17:51
Member 1374210822-Mar-18 17:51 
AnswerRe: Text to Image Font Size Pin
Richard Deeming23-Mar-18 2:46
mveRichard Deeming23-Mar-18 2:46 
QuestionHow to fetch unchecked checkbox value Pin
Member 1372997516-Mar-18 1:25
Member 1372997516-Mar-18 1:25 
AnswerRe: How to fetch unchecked checkbox value Pin
Richard Deeming16-Mar-18 2:50
mveRichard Deeming16-Mar-18 2:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.