How to safely output HTML from a PHP program?

You always want to HTML-encode things inside HTML attributes, which you can do with htmlspecialchars: <span title=”<?php echo htmlspecialchars($variable); ?>”> You probably want to set the second parameter ($quote_style) to ENT_QUOTES. The only potential risk is that $variable may already be encoded, so you may want to set the last parameter ($double_encode) to false.

How do I change the text of an element using JavaScript?

For modern browsers you should use: document.getElementById(“myspan”).textContent=”newtext”; While older browsers may not know textContent, it is not recommended to use innerHTML as it introduces an XSS vulnerability when the new text is user input (see other answers below for a more detailed discussion): //POSSIBLY INSECURE IF NEWTEXT BECOMES A VARIABLE!! document.getElementById(“myspan”).innerHTML=”newtext”;

How to make Bootstrap cards the same height in card-columns?

You can either put the classes on the “row” or the “column”? Won’t be visible on the cards (border) if you use it on the row. https://getbootstrap.com/docs/4.6/utilities/flex/#align-items <div class=”container”> <div class=”row”> <div class=”col-lg-4 d-flex align-items-stretch”> <!–CARD HERE–> </div> <div class=”col-lg-4 d-flex align-items-stretch”> <!–CARD HERE–> </div> <div class=”col-lg-4 d-flex align-items-stretch”> <!–CARD HERE–> </div> </div> </div> UPDATE … Read more

Chrome Download Attribute not working to replace the original name

After some research I have finally found your problem. <a>‘s download attribute: If the HTTP header Content-Disposition: is present and gives a different filename than this attribute, the HTTP header has priority over this attribute. If this attribute is present and Content-Disposition: is set to inline, Firefox gives priority to Content-Disposition, like for the filename … Read more

How do I capture a key press (or keydown) event on a div element?

(1) Set the tabindex attribute: <div id=”mydiv” tabindex=”0″ /> (2) Bind to keydown: $(‘#mydiv’).on(‘keydown’, function(event) { //console.log(event.keyCode); switch(event.keyCode){ //….your actions for the keys ….. } }); To set the focus on start: $(function() { $(‘#mydiv’).focus(); }); To remove – if you don’t like it – the div focus border, set outline: none in the CSS. … Read more

Is it possible to set a src attribute of an img tag in CSS?

Use content:url(“image.jpg”). Full working solution (Live Demo): <!doctype html> <style> .MyClass123{ content:url(“http://imgur.com/SZ8Cm.jpg”); } </style> <img class=”MyClass123″/> Tested and working: Chrome 14.0.835.163 Safari 4.0.5 Opera 10.6 Firefox 100 & newer Tested and Not working: FireFox 40.0.2 (observing Developer Network Tools, you can see that the URL loads, but the image is not displayed) Internet Explorer 11.0.9600.17905 … Read more