I’ve managed to confuse myself here. Basically I am using jQuery to turn a div into a link with;
$('.product').click(function() {
window.open('product.php','jav');
});
This works fine but I am using a .php/MySQL database and I want to be able to pass the product ID into the url so it goes to /product.php#$id. Normally I’d just use <a> tags in my php code but using the Javascript method I can’t plug in the PHP variable to the URL.
Probably not making a lot of sense but it’s been a long day, happy to answer any questions if it’s a little difficult to make out what I’m asking for here.
Emit the product ID as part of the
div‘s markup. Here I’ve shown two options: adata-attribute and the contents of thediv. I’d prefer the data- attribute since your content is probably already defined. You can see all that is below on jsfiddle.Now access it when building your URL: