In my code bellow I would like to replace the string #customer with window.location.hash.
echo '<th><a href="?sort-by=email&order='. $this->order .'#customer">E-Mail</a></th>';
How would it be possible to mix JavaScript with PHP in my case?
This isn't really a matter of PHP.
Just remove the hash as it is right now in the PHP, then we can take it client-side and you can add it there. For instance, you'd make your PHP like this instead:
echo '<th><a href="?sort-by=email&order='. $this->order .'">E-Mail</a></th>';
(Simply removing the hash)
Then in JavaScript, we'd do this:
Element.href = Element.href + window.location.hash;
Where Element is the DOM selector method for the <a> tag.
EDIT Or if you have jQuery handy:
$("a").each(function(){
$(this).attr("href",
$(this).attr("href") + window.location.hash
)
});
a but not if I want it to be a class name?.html() instead for visual reasons)$(".myClass").click(function() { alert('test'); }); and there's nothing happening when I click that item. Not even an error. I will need to figure out what's wrong but thanks anyway for your great answer!