Note that there are some explanatory texts on larger screens.

plurals
  1. POusing HTML tags in basic Javascript that calls an array
    primarykey
    data
    text
    <h1>The Problem</h1> <p>I'm new to this...</p> <p>I have a some basic HTML that contains a circular `div`, that contains a child circular `div` that has an image using the CSS `background-image`, a `h1` and `p` tag is shown using the `:hover` selector.</p> <p>This block of code is repeated twice and wrapped in a `section` tag like so:</p> <pre><code>&lt;section class="col-4"&gt; &lt;div class="img-wrapper"&gt; &lt;a href="#"&gt; &lt;div class="outta-circle"&gt; &lt;div class="text"&gt; &lt;h1 id="news-title-1"&gt;&lt;/h1&gt; &lt;p&gt;Read more...&lt;/p&gt; &lt;/div&gt; &lt;div id="circle1"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/a&gt; &lt;/div&gt; &lt;div class="img-wrapper"&gt; &lt;a href="#"&gt; &lt;div class="outta-circle"&gt; &lt;div class="text"&gt; &lt;h1 id="news-title-2"&gt;&lt;/h1&gt; &lt;p&gt;Read more...&lt;/p&gt; &lt;/div&gt; &lt;div id="circle2"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/a&gt; &lt;/div&gt; &lt;/section&gt; </code></pre> <p>This is the first time I've written Javascript, but I use some basic code to deal with an array that holds news article content (I haven't looked at using the likes of MySQL yet), and some code to deal with changing the `background-image` property's `url()` attribute, which seems to work:</p> <pre><code>var articleArray = [ {img: "img/img-01.jpg", title: "Article Name", content: "This is the content coming from javascript", date: "27/6/2013"}, {img: "img/img-02.jpg", title: "Article Two Name", content: "This is also content coming from javascript", date: "28/6/2013"} ]; S('circle1').backgroundImage = 'url('+articleArray[articleArray.length - 2]["img"]+')'; S('circle2').backgroundImage = 'url('+articleArray[articleArray.length - 1]["img"]+')'; var newsTitle = articleArray[articleArray.length - 2]["title"]; var newsTitle2 = articleArray[articleArray.length - 1]["title"]; O('news-title-1').innerHTML = newsTitle; O('news-title-2').innerHTML = newsTitle2; </code></pre> <p>I have some experience with PHP, and usually I would write a function that parses (that's the right word yeah?) the HTML with the PHP using a `foreach` loop eliminating the need for the duplicate ID tags like `circle1` and `circle2`. I've gone down the Javascript route to because I couldn't work out how to change the `background-image` property's `url()` attribute dynamically, and it's been good to finally look at some Javascript :)</p> <h1>What I'd like</h1> <p>Some advice on best practises so the above code is presented correctly and so I can loop through the array incorporating the HTML, placing the content where it needs to be</p> <p>Please bear in mind my knowledge is limited, I haven't been doing this for long, so it would be appreciated if any help is put down in layman terms.....many thanks!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload