How to move an element into another element?

You may want to use the appendTo function (which adds to the end of the element): $(“#source”).appendTo(“#destination”); Alternatively you could use the prependTo function (which adds to the beginning of the element): $(“#source”).prependTo(“#destination”); Example: $(“#appendTo”).click(function() { $(“#moveMeIntoMain”).appendTo($(“#main”)); }); $(“#prependTo”).click(function() { $(“#moveMeIntoMain”).prependTo($(“#main”)); }); #main { border: 2px solid blue; min-height: 100px; } .moveMeIntoMain { border: 1px … Read more

How do I make a placeholder for a ‘select’ box?

A non-CSS – no JavaScript/jQuery answer: <label>Option name <select> <option value=”” disabled selected>Select your option</option> <option value=”hurr”>Durr</option> </select> </label> Update (December 2021): This works for latest Firefox, Chrome, and Safari. It used to not work for many browsers in the past, as pointed out in the comments.

How do I auto-resize an image to fit a ‘div’ container?

Do not apply an explicit width or height to the image tag. Instead, give it: max-width:100%; max-height:100%; Also, height: auto; if you want to specify a width only. Example: http://jsfiddle.net/xwrvxser/1/ img { max-width: 100%; max-height: 100%; } .portrait { height: 80px; width: 30px; } .landscape { height: 30px; width: 80px; } .square { height: 75px; … Read more

Retrieve the position (X,Y) of an HTML element

The correct approach is to use element.getBoundingClientRect(): var rect = element.getBoundingClientRect(); console.log(rect.top, rect.right, rect.bottom, rect.left); Internet Explorer has supported this since as long as you are likely to care about and it was finally standardized in CSSOM Views. All other browsers adopted it a long time ago. Some browsers also return height and width properties, though … Read more

Vertically align text next to an image?

Actually, in this case it’s quite simple: apply the vertical align to the image. Since it’s all in one line, it’s really the image you want aligned, not the text. <!– moved “vertical-align:middle” style from span to img –> <div> <img style=”vertical-align:middle” src=”https://via.placeholder.com/60×60″ alt=”A grey image showing text 60 x 60″> <span style=””>Works.</span> </div> Tested … Read more

HTML 5: Is it , , or ?

Simply <br> is sufficient. The other forms are there for compatibility with XHTML; to make it possible to write the same code as XHTML, and have it also work as HTML. Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare <br> … Read more

What are valid values for the id attribute in HTML?

For HTML 4, the answer is technically: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-“), underscores (“_”), colons (“:”), and periods (“.”). HTML 5 is even more permissive, saying only that an id must contain at least one character and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)