Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  • Thread Tools
  • Rate This Thread
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    First time trying..

    I am trying to get a div to show once per day.


    This is the original code (Working)
    Code:
    <html> 
    <head> 
    <title></title> 
    
    
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min"></script>
    <script type="text/javascript"> 
    function setDateDiv() { 
    var day = new Date().getDay(); 
    var dayDiv = document.getElementById('dayDiv'); 
    
    switch (day) { 
    case 0: 
    dayDiv.innerHTML = 'Sunday'; 
    break; 
    case 1: 
    dayDiv.innerHTML = 'Monday'; 
    break; 
    case 2: 
    dayDiv.innerHTML = 'Tuesday'; 
    break; 
    case 3: 
    dayDiv.innerHTML = 'Wednesday'; 
    break; 
    case 4: 
    dayDiv.innerHTML = 'Thursday'; 
    break; 
    case 5: 
    dayDiv.innerHTML = 'Friday'; 
    break; 
    case 6: 
    dayDiv.innerHTML = 'Saturday'; 
    break; 
    } 
    } 
    </script> 
    </head> 
    <body onload="setDateDiv();"> 
    <div id="dayDiv"></div> 
    </body> 
    </html>

    I tried to put a div in one of the days:
    Not working now

    <html>
    <head>
    <title></title>
    <style>
    .fragment {
    font-size: 12px;
    font-family: tahoma;
    height: 140px;
    border: 1px solid #ccc;
    color: #555;
    display: block;
    padding: 10px;
    box-sizing: border-box;
    text-decoration: none;
    }

    .fragment:hover {
    box-shadow: 2px 2px 5px rgba(0,0,0,.2);

    }

    .fragment img {
    float: left;
    margin-right: 10px;
    }


    .fragment h3 {
    padding: 0;
    margin: 0;
    color: #369;
    }
    .fragment h4 {
    padding: 0;
    margin: 0;
    color: #000;
    }
    </style>






    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min"></script>
    <script type="text/javascript">
    function setDateDiv() {
    var day = new Date().getDay();
    var dayDiv = document.getElementById('dayDiv');

    switch (day) {
    case 0:
    dayDiv.innerHTML = 'Sunday';
    break;
    case 1:
    dayDiv.innerHTML = '<div id="previewBox">
    <button id="closeButton">Close</button>
    <a class="fragment" href="google.com">
    <div>
    <img src ="http://placehold.it/116x116" alt="some description"/>
    <h3>the title will go here</h3>
    <h4> www.myurlwill.com </h4>
    <p class="text">
    this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etcthis is a short description yada yada peanuts etc
    </p>
    </div>
    </a>
    </div>';
    break;
    case 2:
    dayDiv.innerHTML = 'Tuesday';
    break;
    case 3:
    dayDiv.innerHTML = 'Wednesday';
    break;
    case 4:
    dayDiv.innerHTML = 'Thursday';
    break;
    case 5:
    dayDiv.innerHTML = 'Friday';
    break;
    case 6:
    dayDiv.innerHTML = 'Saturday';
    break;
    }
    }
    </script>
    </head>
    <body onload="setDateDiv();">
    <div id="dayDiv"></div>
    </body>
    </html>
    Last edited by canadacatman; 05-16-2016 at 09:47 PM.

  2. #2
    Regular Coder
    Join Date
    Feb 2016
    Posts
    128
    Thanks
    0
    Thanked 32 Times in 32 Posts
    as soon as I take just text out of the day and put a div with content it will not show up
    Don't understand this. Can you explain more detailed or give a code example demonstrating what you are changing?

  3. #3
    New Coder
    Join Date
    Jun 2006
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I just updated the code to the one that worked before I touched it and what I touched and now not working. Thx

  4. #4
    Regular Coder
    Join Date
    Feb 2016
    Posts
    128
    Thanks
    0
    Thanked 32 Times in 32 Posts
    That's fine, now I understand. If you define a string spanning some lines you have to write a "\" at the end of each line where the string is to be continued:
    Code:
    dayDiv.innerHTML = '<div id="previewBox">\
    <button id="closeButton">Close</button>\
    <a class="fragment" href="google.com">\
    <div>\
    <img src ="http://placehold.it/116x116" alt="some description"/>\
    <h3>the title will go here</h3>\
    <h4> www.myurlwill.com </h4>\
    <p class="text">\
    this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc\ this is a short description yada yada peanuts etcthis is a short description yada yada peanuts etc \
    </p>\
    </div>\
    </a>\
    </div>';
    This works for me.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •