you need to update the product-variants element dataset
var productEl = document.querySelector(".product-variants");
var productDataset = productEl.dataset;
var variants = JSON.parse(productDataset.variants);
productDataset.variantInStock = "true";
productDataset.unselectedOptions = "[]";
// this will select the first variant. change this to whatever logic you have to select the right variant
productDataset.selectedVariant = JSON.stringify(variants[0]);