Jquery append method and colouring of a single word












-2















I need help to append several lines in my webpage using jquery for a tic tac toe game



       <aside >
<h2>History</h2>
<span id="History" > </span> <span id="Won"></span>

</aside>




if(Case1 == "X" && Case2 == "X" && Case3 == "X") {
$("#History").append("Player 1 ")
$("#Won").append("won ").css("color","rgb(240,30,30)")


else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append(" Player 2 ")
$("#Won").append(" Won ").css("color","rgb(240,30,30)")


I need it to display like that after a player win and the "Won" must be in red:
Player 1 won
player 2 won



the issue that i have is i cant make it line by line .. its becomes like this player 1 player 2 won won i tried using but it not good










share|improve this question























  • Please have a look at How to create a Minimal, Complete, and Verifiable example and try to edit your question to meet the criteria.

    – digijay
    Dec 28 '18 at 16:23













  • prntscr.com/m0obd7 i want it to look like that

    – Irfan Slayer
    Dec 28 '18 at 16:24
















-2















I need help to append several lines in my webpage using jquery for a tic tac toe game



       <aside >
<h2>History</h2>
<span id="History" > </span> <span id="Won"></span>

</aside>




if(Case1 == "X" && Case2 == "X" && Case3 == "X") {
$("#History").append("Player 1 ")
$("#Won").append("won ").css("color","rgb(240,30,30)")


else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append(" Player 2 ")
$("#Won").append(" Won ").css("color","rgb(240,30,30)")


I need it to display like that after a player win and the "Won" must be in red:
Player 1 won
player 2 won



the issue that i have is i cant make it line by line .. its becomes like this player 1 player 2 won won i tried using but it not good










share|improve this question























  • Please have a look at How to create a Minimal, Complete, and Verifiable example and try to edit your question to meet the criteria.

    – digijay
    Dec 28 '18 at 16:23













  • prntscr.com/m0obd7 i want it to look like that

    – Irfan Slayer
    Dec 28 '18 at 16:24














-2












-2








-2


0






I need help to append several lines in my webpage using jquery for a tic tac toe game



       <aside >
<h2>History</h2>
<span id="History" > </span> <span id="Won"></span>

</aside>




if(Case1 == "X" && Case2 == "X" && Case3 == "X") {
$("#History").append("Player 1 ")
$("#Won").append("won ").css("color","rgb(240,30,30)")


else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append(" Player 2 ")
$("#Won").append(" Won ").css("color","rgb(240,30,30)")


I need it to display like that after a player win and the "Won" must be in red:
Player 1 won
player 2 won



the issue that i have is i cant make it line by line .. its becomes like this player 1 player 2 won won i tried using but it not good










share|improve this question














I need help to append several lines in my webpage using jquery for a tic tac toe game



       <aside >
<h2>History</h2>
<span id="History" > </span> <span id="Won"></span>

</aside>




if(Case1 == "X" && Case2 == "X" && Case3 == "X") {
$("#History").append("Player 1 ")
$("#Won").append("won ").css("color","rgb(240,30,30)")


else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append(" Player 2 ")
$("#Won").append(" Won ").css("color","rgb(240,30,30)")


I need it to display like that after a player win and the "Won" must be in red:
Player 1 won
player 2 won



the issue that i have is i cant make it line by line .. its becomes like this player 1 player 2 won won i tried using but it not good







javascript jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 16:16









Irfan SlayerIrfan Slayer

31




31













  • Please have a look at How to create a Minimal, Complete, and Verifiable example and try to edit your question to meet the criteria.

    – digijay
    Dec 28 '18 at 16:23













  • prntscr.com/m0obd7 i want it to look like that

    – Irfan Slayer
    Dec 28 '18 at 16:24



















  • Please have a look at How to create a Minimal, Complete, and Verifiable example and try to edit your question to meet the criteria.

    – digijay
    Dec 28 '18 at 16:23













  • prntscr.com/m0obd7 i want it to look like that

    – Irfan Slayer
    Dec 28 '18 at 16:24

















Please have a look at How to create a Minimal, Complete, and Verifiable example and try to edit your question to meet the criteria.

– digijay
Dec 28 '18 at 16:23







Please have a look at How to create a Minimal, Complete, and Verifiable example and try to edit your question to meet the criteria.

– digijay
Dec 28 '18 at 16:23















prntscr.com/m0obd7 i want it to look like that

– Irfan Slayer
Dec 28 '18 at 16:24





prntscr.com/m0obd7 i want it to look like that

– Irfan Slayer
Dec 28 '18 at 16:24












1 Answer
1






active

oldest

votes


















0














You should be appending new elements not just words into the divs as well as line breaks with the br tag and make your container elements divs instead of spans as spans are inline, use float-left and float-right on the divs to keep them aligned horizontally, also it is good practice to start using CSS files to style your elements instead of doing inline styling, so make some CSS classes for your divs and the spans which you will be appending to the divs to set the color, to be honest I don't think you need two divs but if so and the space between is too much you can add margin-right to the right floating div to reduce the space between text in left div and right div:



CSS:



.divLeft{
float: left;
}

.divRight{
float: right;
margin-right: 85%;
}

.spanText{
color: rgb(240, 30, 30);
}


HTML:



<aside >
<h2>History</h2>
<div class="divLeft" id="History" > </div> <div class="divRight" id="Won"></div>

</aside>


JQUERY:



if(Case1 == "X" && Case2 == "X" && Case3 == "X") {

$("#History").append("<span class='spanText'>Player 1 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append("<span class='spanText'>Player 2 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}


JSFiddle:



https://jsfiddle.net/tu9rdpw3/4/






share|improve this answer


























  • i dont want to clear the old values the game goes on and the history is not cleared

    – Irfan Slayer
    Dec 28 '18 at 16:21











  • @IrfanSlayer One moment then, fixing the answer.

    – Ryan Wilson
    Dec 28 '18 at 16:21











  • prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

    – Irfan Slayer
    Dec 28 '18 at 16:23











  • @IrfanSlayer I added more to the answer, I hope this gives you what you need.

    – Ryan Wilson
    Dec 28 '18 at 16:40











  • thanks man its very helpful

    – Irfan Slayer
    Dec 28 '18 at 16:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961334%2fjquery-append-method-and-colouring-of-a-single-word%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You should be appending new elements not just words into the divs as well as line breaks with the br tag and make your container elements divs instead of spans as spans are inline, use float-left and float-right on the divs to keep them aligned horizontally, also it is good practice to start using CSS files to style your elements instead of doing inline styling, so make some CSS classes for your divs and the spans which you will be appending to the divs to set the color, to be honest I don't think you need two divs but if so and the space between is too much you can add margin-right to the right floating div to reduce the space between text in left div and right div:



CSS:



.divLeft{
float: left;
}

.divRight{
float: right;
margin-right: 85%;
}

.spanText{
color: rgb(240, 30, 30);
}


HTML:



<aside >
<h2>History</h2>
<div class="divLeft" id="History" > </div> <div class="divRight" id="Won"></div>

</aside>


JQUERY:



if(Case1 == "X" && Case2 == "X" && Case3 == "X") {

$("#History").append("<span class='spanText'>Player 1 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append("<span class='spanText'>Player 2 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}


JSFiddle:



https://jsfiddle.net/tu9rdpw3/4/






share|improve this answer


























  • i dont want to clear the old values the game goes on and the history is not cleared

    – Irfan Slayer
    Dec 28 '18 at 16:21











  • @IrfanSlayer One moment then, fixing the answer.

    – Ryan Wilson
    Dec 28 '18 at 16:21











  • prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

    – Irfan Slayer
    Dec 28 '18 at 16:23











  • @IrfanSlayer I added more to the answer, I hope this gives you what you need.

    – Ryan Wilson
    Dec 28 '18 at 16:40











  • thanks man its very helpful

    – Irfan Slayer
    Dec 28 '18 at 16:46
















0














You should be appending new elements not just words into the divs as well as line breaks with the br tag and make your container elements divs instead of spans as spans are inline, use float-left and float-right on the divs to keep them aligned horizontally, also it is good practice to start using CSS files to style your elements instead of doing inline styling, so make some CSS classes for your divs and the spans which you will be appending to the divs to set the color, to be honest I don't think you need two divs but if so and the space between is too much you can add margin-right to the right floating div to reduce the space between text in left div and right div:



CSS:



.divLeft{
float: left;
}

.divRight{
float: right;
margin-right: 85%;
}

.spanText{
color: rgb(240, 30, 30);
}


HTML:



<aside >
<h2>History</h2>
<div class="divLeft" id="History" > </div> <div class="divRight" id="Won"></div>

</aside>


JQUERY:



if(Case1 == "X" && Case2 == "X" && Case3 == "X") {

$("#History").append("<span class='spanText'>Player 1 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append("<span class='spanText'>Player 2 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}


JSFiddle:



https://jsfiddle.net/tu9rdpw3/4/






share|improve this answer


























  • i dont want to clear the old values the game goes on and the history is not cleared

    – Irfan Slayer
    Dec 28 '18 at 16:21











  • @IrfanSlayer One moment then, fixing the answer.

    – Ryan Wilson
    Dec 28 '18 at 16:21











  • prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

    – Irfan Slayer
    Dec 28 '18 at 16:23











  • @IrfanSlayer I added more to the answer, I hope this gives you what you need.

    – Ryan Wilson
    Dec 28 '18 at 16:40











  • thanks man its very helpful

    – Irfan Slayer
    Dec 28 '18 at 16:46














0












0








0







You should be appending new elements not just words into the divs as well as line breaks with the br tag and make your container elements divs instead of spans as spans are inline, use float-left and float-right on the divs to keep them aligned horizontally, also it is good practice to start using CSS files to style your elements instead of doing inline styling, so make some CSS classes for your divs and the spans which you will be appending to the divs to set the color, to be honest I don't think you need two divs but if so and the space between is too much you can add margin-right to the right floating div to reduce the space between text in left div and right div:



CSS:



.divLeft{
float: left;
}

.divRight{
float: right;
margin-right: 85%;
}

.spanText{
color: rgb(240, 30, 30);
}


HTML:



<aside >
<h2>History</h2>
<div class="divLeft" id="History" > </div> <div class="divRight" id="Won"></div>

</aside>


JQUERY:



if(Case1 == "X" && Case2 == "X" && Case3 == "X") {

$("#History").append("<span class='spanText'>Player 1 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append("<span class='spanText'>Player 2 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}


JSFiddle:



https://jsfiddle.net/tu9rdpw3/4/






share|improve this answer















You should be appending new elements not just words into the divs as well as line breaks with the br tag and make your container elements divs instead of spans as spans are inline, use float-left and float-right on the divs to keep them aligned horizontally, also it is good practice to start using CSS files to style your elements instead of doing inline styling, so make some CSS classes for your divs and the spans which you will be appending to the divs to set the color, to be honest I don't think you need two divs but if so and the space between is too much you can add margin-right to the right floating div to reduce the space between text in left div and right div:



CSS:



.divLeft{
float: left;
}

.divRight{
float: right;
margin-right: 85%;
}

.spanText{
color: rgb(240, 30, 30);
}


HTML:



<aside >
<h2>History</h2>
<div class="divLeft" id="History" > </div> <div class="divRight" id="Won"></div>

</aside>


JQUERY:



if(Case1 == "X" && Case2 == "X" && Case3 == "X") {

$("#History").append("<span class='spanText'>Player 1 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}else if(Case1 == "O" && Case2 == "O" && Case3 == "O") {
$("#History").append("<span class='spanText'>Player 2 </span><br/>");
$("#Won").append("<span class='spanText'>won</span><br/>");
}


JSFiddle:



https://jsfiddle.net/tu9rdpw3/4/







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 28 '18 at 16:45

























answered Dec 28 '18 at 16:20









Ryan WilsonRyan Wilson

3,6791518




3,6791518













  • i dont want to clear the old values the game goes on and the history is not cleared

    – Irfan Slayer
    Dec 28 '18 at 16:21











  • @IrfanSlayer One moment then, fixing the answer.

    – Ryan Wilson
    Dec 28 '18 at 16:21











  • prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

    – Irfan Slayer
    Dec 28 '18 at 16:23











  • @IrfanSlayer I added more to the answer, I hope this gives you what you need.

    – Ryan Wilson
    Dec 28 '18 at 16:40











  • thanks man its very helpful

    – Irfan Slayer
    Dec 28 '18 at 16:46



















  • i dont want to clear the old values the game goes on and the history is not cleared

    – Irfan Slayer
    Dec 28 '18 at 16:21











  • @IrfanSlayer One moment then, fixing the answer.

    – Ryan Wilson
    Dec 28 '18 at 16:21











  • prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

    – Irfan Slayer
    Dec 28 '18 at 16:23











  • @IrfanSlayer I added more to the answer, I hope this gives you what you need.

    – Ryan Wilson
    Dec 28 '18 at 16:40











  • thanks man its very helpful

    – Irfan Slayer
    Dec 28 '18 at 16:46

















i dont want to clear the old values the game goes on and the history is not cleared

– Irfan Slayer
Dec 28 '18 at 16:21





i dont want to clear the old values the game goes on and the history is not cleared

– Irfan Slayer
Dec 28 '18 at 16:21













@IrfanSlayer One moment then, fixing the answer.

– Ryan Wilson
Dec 28 '18 at 16:21





@IrfanSlayer One moment then, fixing the answer.

– Ryan Wilson
Dec 28 '18 at 16:21













prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

– Irfan Slayer
Dec 28 '18 at 16:23





prntscr.com/m0obd7 i want it to look the that ^^ if possible ty

– Irfan Slayer
Dec 28 '18 at 16:23













@IrfanSlayer I added more to the answer, I hope this gives you what you need.

– Ryan Wilson
Dec 28 '18 at 16:40





@IrfanSlayer I added more to the answer, I hope this gives you what you need.

– Ryan Wilson
Dec 28 '18 at 16:40













thanks man its very helpful

– Irfan Slayer
Dec 28 '18 at 16:46





thanks man its very helpful

– Irfan Slayer
Dec 28 '18 at 16:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961334%2fjquery-append-method-and-colouring-of-a-single-word%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas