javascript - how to set a class and id to a div that don't affect each other by jquery? -


i made simple chat room. want comment have different parts use code set id , class div

$('<div id="fullbox">'+inpx+'</div>').addclass('showmessage').appendto('#mainbox'); 

i use #fullbox have div has larger space , use .showmessage have smaller space hold text.

therefor can use larger space add element later.

style of id , class

#fullbox{ width:1100px; margin:5px; background-color:#fff;   } 

and class

.showmessage{ width :1000 px; background-color:#03c; word-wrap:break-word; line-height :1.3 em; font-size :24 px; } 

my id has larger space , expect class smaller space hold text text follow id don't know how solve it.

i use 2 different background color see both of them if can see both of them answer.

link code :jsfiddle

and want know how can have auto scrollbar automatic show new post.

to fill space have set width:100% presented below.

$(document).ready(function() {    $('.btn').on('click', function() {      var inpx = $('.inbox').val();      $('.inbox').val("");      $('<div id="fullbox">' + inpx + '</div>').addclass('showmessage').appendto('#mainbox');      });  });
#mainbox {    margin-top: 10px;    float: left;    width: 500px;    height: 200px;    margin-left: 9px;    background: url(../img/dash.png);    box-shadow: -1px 2px 1px #dcdcdc;    border: 1px solid #c9c9c9;    border-radius: 5px;    border-left: 0.5em solid #06f;    z-index: 900;    overflow-y: auto;  }  #bottombox {    margin-top: 10px;    float: left;    width: 500px;    height: 100px;    margin-left: 9px;    background: url(../img/dash.png);    box-shadow: -1px 2px 1px #dcdcdc;    border: 1px solid #c9c9c9;    border-radius: 5px;    border-left: 0.5em solid #06f;  }  .inbox {    margin-top: 30px;    width: 400px;    height: 30px;    margin-left: 5px;    font-family: gotham, "helvetica neue", helvetica, arial, sans-serif;    font-size: 18px;    resize: none;  }  .btn {    position: relative;    top: -18px;    margin-left: 5px;    width: 60px;    height: 65px;    font-family: gotham, "helvetica neue", helvetica, arial, sans-serif;    font-size: 18px;  }  #fullbox {    width: 100%;    margin: 5px;    background-color: #ccc;  }  .showmessage {    width: 100%;    background-color: #000;    word-wrap: break-word;    line-height: 1.3em;    font-size: 24px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div id="mainbox"></div>  <div id="bottombox">    <form>      <textarea class="inbox"></textarea>      <input type="button" class="btn" value="send">    </form>  </div>

or better can remove width elements (fullbox , showmessage) , inherited parent.

$(document).ready(function() {    $('.btn').on('click', function() {      var inpx = $('.inbox').val();      $('.inbox').val("");      $('<div id="fullbox">' + inpx + '</div>').addclass('showmessage').appendto('#mainbox');    });  });
#mainbox {    margin-top: 10px;    float: left;    width: 500px;    height: 200px;    margin-left: 9px;    background: url(../img/dash.png);    box-shadow: -1px 2px 1px #dcdcdc;    border: 1px solid #c9c9c9;    border-radius: 5px;    border-left: 0.5em solid #06f;    z-index: 900;    overflow-y: auto;  }  #bottombox {    margin-top: 10px;    float: left;    width: 500px;    height: 100px;    margin-left: 9px;    background: url(../img/dash.png);    box-shadow: -1px 2px 1px #dcdcdc;    border: 1px solid #c9c9c9;    border-radius: 5px;    border-left: 0.5em solid #06f;  }  .inbox {    margin-top: 30px;    width: 400px;    height: 30px;    margin-left: 5px;    font-family: gotham, "helvetica neue", helvetica, arial, sans-serif;    font-size: 18px;    resize: none;  }  .btn {    position: relative;    top: -18px;    margin-left: 5px;    width: 60px;    height: 65px;    font-family: gotham, "helvetica neue", helvetica, arial, sans-serif;    font-size: 18px;  }  #fullbox {    margin: 5px;    background-color: #ccc;  }  .showmessage {    background-color: #000;    word-wrap: break-word;    line-height: 1.3em;    font-size: 24px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div id="mainbox"></div>  <div id="bottombox">    <form>      <textarea class="inbox"></textarea>      <input type="button" class="btn" value="send">    </form>  </div>

and see last message, can use scrolltop set vertical position of scrollbar.

$(document).ready(function() {    $('.btn').on('click', function() {      var inpx = $('.inbox').val();      $('.inbox').val("");      $('<div id="fullbox">' + inpx + '</div>').addclass('showmessage').appendto('#mainbox');      $('#mainbox').scrolltop($('#mainbox').height());    });  });
#mainbox {    margin-top: 10px;    float: left;    width: 500px;    height: 200px;    margin-left: 9px;    background: url(../img/dash.png);    box-shadow: -1px 2px 1px #dcdcdc;    border: 1px solid #c9c9c9;    border-radius: 5px;    border-left: 0.5em solid #06f;    z-index: 900;    overflow-y: auto;  }  #bottombox {    margin-top: 10px;    float: left;    width: 500px;    height: 100px;    margin-left: 9px;    background: url(../img/dash.png);    box-shadow: -1px 2px 1px #dcdcdc;    border: 1px solid #c9c9c9;    border-radius: 5px;    border-left: 0.5em solid #06f;  }  .inbox {    margin-top: 30px;    width: 400px;    height: 30px;    margin-left: 5px;    font-family: gotham, "helvetica neue", helvetica, arial, sans-serif;    font-size: 18px;    resize: none;  }  .btn {    position: relative;    top: -18px;    margin-left: 5px;    width: 60px;    height: 65px;    font-family: gotham, "helvetica neue", helvetica, arial, sans-serif;    font-size: 18px;  }  #fullbox {    margin: 5px;    background-color: #ccc;  }  .showmessage {    background-color: #000;    word-wrap: break-word;    line-height: 1.3em;    font-size: 24px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div id="mainbox"></div>  <div id="bottombox">    <form>      <textarea class="inbox"></textarea>      <input type="button" class="btn" value="send">    </form>  </div>


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -