Image center align vertically and horizontally [duplicate]

There’s a few good ways to both horizontally and vertically center an element, it just comes down to the situation and your preference. With the following markup: <div><img src=”https://stackoverflow.com/questions/5481821/a.png” width=”100″ height=”100″></div> line-height div { width:300px; height:300px; line-height:300px; text-align:center; } div img { vertical-align:middle; } Good quick fix without messing with positioning too much but if … Read more

HTML canvas with scrollbar

Specify the total width of the canvas then wrap it in a div. Set the div to overflow: scroll and give that the 500px width. You should then have scrollbars allowing you to scroll and see the hidden parts of the canvas. Repeat this for all of the canvases. <div style=”max-height: 256px;max-width:256px;overflow: scroll;”> <canvas height=”512px” … Read more

Parsing returned HTML from jQuery AJAX request

Your code works fine. You just aren’t using jsFiddle’s API correctly. Check the docs for /echo/html/ (http://doc.jsfiddle.net/use/echo.html#html): URL: /echo/html/ Data has to be provided via POST So, you need to update your AJAX call to use POST. Also the trailing slash is needed. $(function () { $.ajax({ url: “/echo/html/”, type: “post”, dataType: “html”, success: function … Read more

Get Clicked from

You can use event.target for this: JS: // IE does not know about the target attribute. It looks for srcElement // This function will get the event target in a browser-compatible way function getEventTarget(e) { e = e || window.event; return e.target || e.srcElement; } var ul = document.getElementById(‘test’); ul.onclick = function(event) { var target … Read more

jQuery remove tag from HTML String without RegEx

You can wrap your string in a jQuery object and do some sort of a manipulation like this: var removeElements = function(text, selector) { var wrapped = $(“<div>” + text + “</div>”); wrapped.find(selector).remove(); return wrapped.html(); } USAGE var removedSpanString = removeElements(“<span>Some Text</span> Some other Text”, “span”); The beauty of this approach is that you can … Read more