I am currently trying to apply some CSS to certain div elements on my webpage.
Here is the HTML code snippet:
<div class="data-item">
<a class="title" id="cms-occasion" style="font-size: 14px !important;" href="#">Gift for a Graduate</a>
<div></div>
</div>
<div class="data-item">
<a class="title" id="cms-occasion" style="font-size: 14px !important;" href="#">Driving Experience Gift</a>
<div></div>
</div>
<div class="data-item">
<a class="title" id="cms-occasion" style="font-size: 14px !important;" href="#">Gift Ideas</a>
<div></div>
</div>
Next, here is the JavaScript function I wrote that seems to have errors:
var giftIdea = document.getElementById('cms-occasion').innerHTML.indexOf('Gift Ideas');
if (giftIdea != -1){
giftIdea.style.display = 'block';
giftIdea.style.width = '100%';
giftIdea.style.bottom = '-117px';
giftIdea.style.textAlign = 'left'; //Changed from text-align
giftIdea.style.position = 'absolute';
giftIdea.style.backgroundColor = '#535353'; //Changed from background-color
giftIdea.style.padding = '6px';
}
Could someone please help me identify the issues in my JS function?
Thank you in advance!