I have code that was working with Jquery however I have been asked to convert to pure Javascript as there a preference for using JS only.
I have tried without success and also tried to use an online converter but this didn’t work great and was still giving errors.
Just wondering if someone could take a look at the jquery code that was working for suggestions on how to get the same working with Javascript only.
$('.one').click(function () {
$(this).toggleClass('selected');
$('.two').removeClass('selected');
});
$('.two').click(function () {
$(this).toggleClass('selected');
$('.one').removeClass('selected');
});
$('.ready').click(function () {
if ($(".one").hasClass("selected")) {
$("#sec-1").hide();
$("#sec-2").show();
}
else if($(".two").hasClass("selected")) {
$("#sec-1").show();
$("#sec-2").hide();
}
});
$('.return').click(function () {
$("#sec-1").show();
$("#sec-2").hide();
$("#grid").empty();
});
obj = JSON.parse(json-data-1);
obj1 = JSON.parse(json-data-2);
//create objects
function Product(image, title, link) {
this.image = image;
this.title = title;
this.link = link;
}
// Create Product Objects
var used = false;
$('.btn-test').click(function (e) {
if (used == false) {
used = true;
e.preventDefault();
$("#grid").append("<br/><p class='hello'>Hello " + $('#txt_name').val() + " , <br/><br/> here's the output </p>");
if ($(".testclass").hasClass("selected")) {
for(var i=0; i<obj.Products.length; i++) {
new Product("obj.Products[i].image", "obj.Products[i].title", "obj.Products[i].link");
$("#grid").append("<div class='grid-item'><div><img src='" + obj.Products[i].image + "</p> </div><div>" + obj.Products[i].price + "</div><div class='prod'> <a class='product' href='" + obj.Products[i].link + "'>Go to Product Page" + "</a></div></div>");
}
$("#grid").append("<br/><p class='grid-link'><a href=" + '' + ">Go to</a></p>");
}
else if ($(".testclass1").hasClass("selected")) {
for(var i=0; i<obj1.Products.length; i++) {
new Product("obj1.Products[i].image", "obj1.Products[i].title", "obj1.Products[i].link");
$("#grid").append("<div class='grid-item'><div><img src='" + obj1.Products[i].image + "</p> </div><div>" + obj1.Products[i].price + "</div><div class='prod'> <a class='product' href='" + obj1.Products[i].link + "'>Go to Product Page" + "</a></div></div>");
}
$("#grid").append("<br/><p class='grid-link'><a href=" + '' + ">Go to</a></p>");
}
}
used = false;
});
Thanks for any help.