Tag: dom

Optimize Huge JSON response

I am working on a Big Data client side application. Server language is Java. Within Frontend I have heavily vanilla JavaScript but AngularJS as MVC framework. Problem Dealing with big data analysis, at a time a single REST api response is around 1.5MB to 3MB. Dealing with this data to construct DOM is a pain. […]

JS: remove lastChild only works every second button click

I use this code to delete the last item of an <ul> list, but only on the second, fourth, sixth, … every second click on the button the item gets removed, but every click the message appears. What can I do that the element gets deleted on every click. document.getElementsByTagName(‘input’)[0].onclick = function () { ‘use […]

Why does firstChild not return the first element?

I was writing some code the other day, and for some reason, I had no idea why this happened, but this was part of the code that I had written. var item = document.getElementByClass(‘object’); var innerImageId = item.firstChild.id; I went over this code a lot of times. The problem of this code is that the […]

How to tell if an element is a child of another element in JavaScript (no jQuery)?

If I have 2 HTML elements, how can I easily tell if 1 is a child of the other? var parent = document.getElementById(‘shapes’); var child = document.getElementById(‘star’); Is there any kind of function on an element like child.getParentElement() that I could compare with like child.getParentElement() == parent? I understand parent.children gives me back an array […]

Finding the location of a TD in a table

So let’s say I have a table, and I want to manipulate a specific <td> in it: HTML: <table> <tr><td>1</td> <td>2</td></tr> <tr><td>3</td> <td>4</td></tr> <tr><td id=”hi”>5</td> <td>6</td></tr> </table> Javascript: document.getElementsByTagName(“table”)[0].rows[2].cells[0]; This will help me REACH a specific cell in a table. My question is this: Say I have a specific <td> inside a table: var td […]

Does jQuery can use an end tag as a selector?

I am pretty new in jQuery. I cam across this jQuery code that uses <div /> as a selector: $(“<div />”).html(someString).text(); First of all, I would like to know if it is a legitimate tag to use, since div has an end tag: </div>. But my main question – does jQuery can use an end […]

How to get the value of data attribute using jquery

I am working on a node.js application which generates a html page. This html page displays a list of associates built according to the data passed onto this page. A list is built something like as follows: <ul class=”notification-body” style=””> //loop for all assocaite id’s passed to this page <li class=”testClass” data-associateid=”<%= assocID %>”> <span> […]

Detecting user tampering with DOM

I’ve written a web app that uses an ad banner on the side to support free accounts. Problem is, since the ad is loaded in its own <div>, it’s relatively easy to go into developer/debug console in any modern browser and either remove the div or resize the ad to 0px using CSS overrides (the […]

“push” is not a function [on elements returned by getElementsByTagName]

I have a bit of Javascript where I’m POSTing my form with an XMLHttpRequest, which otherwise works fine, but when I try to add the SELECT values to the array of INPUT values, it seems Javascript has lost its mind (or I have). This function just builds the “name1=value1&name2=value2” string and passes it along. The […]

How do I remove an element from the DOM, given its id?

In this specific case, the element is a table row.