Comments on: JavaScript and DOM API fuss https://j11y.io/javascript/javascript-and-dom-api-fuss/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Angel https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2162 Wed, 22 Aug 2012 04:59:24 +0000 https://j11y.io/?p=1854#comment-2162 Its really simple to work with DOM and i am working with DOM since last several years.
@Jani Hartikainen I accept that jQuery improves the situation but thats also true, to work with jQuery is bit complex than DOM.

]]>
By: SEAN https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2161 Tue, 14 Aug 2012 06:17:50 +0000 https://j11y.io/?p=1854#comment-2161 Well I am beginner and also an amateur in programming so I won’t comment on the issue directly but in my experience I have seen mixing can help if we know the proportions. May be we need to search the correct proportion here to get a beautiful programme using both business and presentation logic.

]]>
By: Valeria Sanders https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2160 Sun, 05 Aug 2012 10:28:11 +0000 https://j11y.io/?p=1854#comment-2160 An article worth reading. This article clearly suggests its not good to incorporate DOM logic into the presentation logic as DOM itself does the job of presentation. An amateur with JS, I look forward for more updates.

]]>
By: Jones https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2159 Thu, 26 Jul 2012 09:11:22 +0000 https://j11y.io/?p=1854#comment-2159 Hi All,

I am having some problems with DOM, I know this is not exactly on the topic going on here but please Can anyone help me?

I let the user create images and buttons (a button with image above it)by clicking on a button: “new_a_window” so I use append() in jQuery. But the question is that I have to get the different image as the user press on it.

As the user click the “new_a_window” button, jQuery will create a button with a image in a jDialog(story_pages).

$( ‘#new_a_window’).bind(‘click’,function(){
$(‘#story_pages’).append(‘

‘);
window_value= window_value+1; // I give each of the images a unique integer value
// since of the value is the index of a image array.
})

I have to implement the scenario:

As the user presses on the image button, I can get the image’s value. However, after appending the code snippet above, each image’s value is “window_value”, I can’t select it by value. How can I do?

Please help me…… 🙁

]]>
By: Walker Allison https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2158 Mon, 02 Jul 2012 07:46:23 +0000 https://j11y.io/?p=1854#comment-2158 I recently wrote some code to filter nodes from a DOM and had issues with NullPointerExceptions:

NodeList nl = doc.getElementsByTagName(“mytag”);
for(int i = 0, n = nl.getLength(); i < n; i++) {
Element elt = (Element) nl.item(i);
if(…) {
elt.getParentNode().removeChild(elt);
}
}
The problem was that NodeLists are live, and removing elements while iterating changes the indexes. When I tried to retrieve an element past the end, nl.item(i) returned null. Even changing the loop to this wouldn’t fix it: for(int i = 0; i < nl.getLength(); i++). The problem then is that if element i is removed, the element that was at index i+1 is now at index i and won’t be checked. I ended up using this code:

NodeList nl = doc.getElementsByTagName("mytag");
for(int i = 0, n = nl.getLength(); i < n; i++) {
Element elt = (Element) nl.item(i);
if(…) {
elt.getParentNode().removeChild(elt);
i–;
n–;
}
}
Please correct me. 🙂

]]>
By: Roma https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2157 Wed, 04 Apr 2012 18:22:54 +0000 https://j11y.io/?p=1854#comment-2157 Can you do an article/tutorial on “Separation of business logic and presentation logic” since what I think this article touched up on. And the difference between the two. This way more people will be aware. And hopefully I will learn to do it the right way for a change.

]]>
By: MARTIN https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2156 Thu, 29 Mar 2012 17:25:48 +0000 https://j11y.io/?p=1854#comment-2156 These examples are saying it’s not a good idea to mix DOM logic and presentation logic, which seems like a fine practice to me since the DOM is the presentation.

]]>
By: Paul Grenier https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2155 Fri, 02 Sep 2011 02:02:45 +0000 https://j11y.io/?p=1854#comment-2155 When I was doing iPhone stuff with phoneGap I noticed that having a JavaScript object holding my database greatly improved my performance since I didn’t do unnecessary reads/writes. The database just persisted state across sessions, my real state was held in memory.

Now I’m working on a rather large application for an insurance firm with hundreds of form fields. When we started, the DOM held state. “Is the field visible? Ask the field $(“#blah”).isVisible().” With a very complicated DOM structure and complex business logic, this style of app just wouldn’t perform. Once we treated the DOM like a slow, clunky database and used a fast state control layer in memory to filter “reads and writes” we performed much better. If the field is already visible, don’t invoke jQuery to call visible(). Once we made this view-model layer, we realized we didn’t need sizzle anymore and the app got even faster.

Go with MVVM, it’s the right choice but you won’t really see the difference until the app has to scale.

]]>
By: Jim https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2154 Mon, 29 Aug 2011 15:22:04 +0000 https://j11y.io/?p=1854#comment-2154 If it’s any consolation, I’m wrestling with the same questions – as are many of the developers I work with. A previous commenter said that this was really about moving towards “MVC” – and while I agree with that, it’s possibly more accurate to call it MVVM, in that it seems you are advocating a “DOM proxy object”…or….in MVVM terms, a model who’s sole purpose is to contain data and view behavior for a given view. At the very least, I think devs like us need to be exploring this territory – perhaps one of us will stumble upon something useful. Knockoutjs is becoming popular, and I initially loved it, but that love has cooled significantly the more I’ve thought about how it’s not naturally unobtrusive (and I have some complaints regarding performance and API as well). Other competitors (like Angular and Batman) aren’t unobtrusive either. There *has* to be better ways to do this stuff, and I commend you for asking those questions, and being willing to take the heat from all the jQuery-is-my-spaghetti-code-hammer-and-you-look-like-a-nail fan boys. 🙂

]]>
By: Dave https://j11y.io/javascript/javascript-and-dom-api-fuss/#comment-2153 Mon, 29 Aug 2011 13:13:08 +0000 https://j11y.io/?p=1854#comment-2153 Certainly a lot of us have learned that not a good idea to mix business logic and presentation logic. These examples are saying it’s not a good idea to mix DOM logic and presentation logic, which seems like a fine practice to me since the DOM is the presentation. jQuery’s .data() API certainly can be used poorly, but take a look at jQuery UI for some examples of how to use it well.

In that final example regarding the active flag, the use of .data() is much better in that when the div is removed the data will disappear with it, automagically. Imagine each div represents a comment in a large and ever-changing comment stream. What is the lifetime of the closure variable?

Imagine the div is instead a textarea, and instead of a custom active variable we use the DOM’s built-in disabled property to manage state and CSS to manage appearance. Is that still bad? Do we really need to create an entire JavaScript object to manage a variable that mirrors the state of the DOM property?

]]>