I used a foreach loop in jQuery to create some divs. Everything seems to be working fine, but for some reason, my divs are missing SOME class properties. Here is the code snippet I am using:
$("#item-container").append("<div class=\"panel col-md-2 col-xs-4 item\" style=\"height:170px; border-bottom-color: red;\"></div>")
So basically, just simple divs. I added some styling like this:
.item {
margin: 10;
border-style: solid;
cursor: pointer;
border-bottom-width: 2px;
}
The styling works perfectly fine. However, I have another JavaScript function that changes the color of the selected div with the class item. This function was working without any issues when I generated the divs with PHP, but now it's not working. Additionally, the above styling is not being applied for some unknown reason.
item h5,h6,img{
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none;
-webkit-user-drag: none;
-khtml-user-drag: none;
-moz-user-drag: none;
-o-user-drag: none;
user-drag: none;
If you have any insights on what might be causing this issue, please let me know
EDIT: I figured out why the CSS is not working. The problem lies within this particular function:
$('.item').click(function () {
var currentprice
var itemprice
itemprice = parseFloat($(this).find('.item-price').html());
currenptice = $('#currentprice').text();
if ($(this).hasClass( "selected-item" )) {
$('#currentprice').text(parseFloat(currenptice) - itemprice);
$(this).removeClass("selected-item");
} else {
$('#currentprice').text(parseFloat(currenptice) + itemprice);
$(this).addClass("selected-item");
}
});
This function worked perfectly when I was generating divs with PHP, but now it's not functioning properly.