jQuery document.createElement equivalent?

I’m refactoring some old JavaScript code and there’s a lot of DOM manipulation going on. var d = document; var odv = d.createElement(“div”); odv.style.display = “none”; this.OuterDiv = odv; var t = d.createElement(“table”); t.cellSpacing = 0; t.className = “text”; odv.appendChild(t); I would like to know if there is a better way to do this using … Read more

How can I select an element by name with jQuery?

I have a table column I’m trying to expand and hide. jQuery seems to hide the <td> elements when I select it by class but not by the element’s name. For example: $(“.bold”).hide(); // Selecting by class works. $(“tcol1”).hide(); // Selecting by name does not work. Note the HTML below. The second column has the … Read more

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

I want to know how to get the X and Y position of HTML elements such as img and div in JavaScript. 2 29 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 … Read more

.prop() vs .attr()

So jQuery 1.6 has the new function prop(). $(selector).click(function(){ //instead of: this.getAttribute(‘style’); //do i use: $(this).prop(‘style’); //or: $(this).attr(‘style’); }) or in this case do they do the same thing? And if I do have to switch to using prop(), all the old attr() calls will break if i switch to 1.6? UPDATE selector=”#id” $(selector).click(function() { … Read more