I am currently learning JavaScript and jQuery, with a strong grasp on HTML/CSS. I am working on developing a single-page front-end website using Bootstrap for layout design. My main focus now is on implementing functionality. Here is the scenario:
There are 4 <div>
elements, each containing text and an image; below them is a <div>
with the class #content
. Each of the #c1-4 divs has a click listener that triggers a change in the content displayed within the #content div.
<div id="#c1" class="active-div">
<p>Text Here</p>
<img src="image.jpg">
</div>
<div id="#c2">
<p>Text 2 Here</p>
<img src="image2.jpg">
</div>
<div id="#c3">
<p>Text 3 Here</p>
<img src="image3.jpg">
</div>
<div id="#c4">
<p>Text 4 Here</p>
<img src="image4.jpg">
</div>
<div id="#content">
<!-- Content of the selected div goes here -->
</div>
The default selection is #c1 <div>
. The content within #content includes text, icons, and images styled appropriately.
The Question: What is the most effective way to store and load content into the #content div? These are the options I am considering based on my current knowledge:
Hard-coding content into the JS file and using .html() to set the content. However, this approach may result in a large amount of HTML code inside the JS file.
Creating separate divs for each of the #c IDs and toggling visibility using .show() and .hide().
Utilizing .load() to fetch content from another HTML document. Concerns include styling issues and potential impact on the display of the #content div.
I would like to understand the advantages and disadvantages of each method, as well as which one would be easier to maintain in the future (e.g., adding more numbered #c divs).