I know that there are plenty answers to this question on stackoverflow, but I can´t find one that give me an answer that can help me to solve a question that came out after read a lot of Javascript, JQuery articles and using those languages for several months.
Here is the deal:
Apparently, I can do a generic site that can charge a Dom dynamically, I read article that says that do this and adding element to the dom at the time the page is loading is dangerous, and use this on framework like Angularjs is almost a sin to think on angular as a jquery background.
So, with that in mind.
Why is such a big deal to make a Dom loading dynamically (input a Json File)?
And the finally Question is, there’s a right way to do it?
Thanks in advance!
3
I think you should use jQuery when you manipulate an existing DOM.
Of course with jQuery you can insert HTML snippets too, but i think its harder to separate the view from the js code in this way.
In Angular you define the view in HTML and the js code will make it workable.
I can summarise the main difference between the jquery and the angular way:
- with jquery you manipulate DOM (and handle events)
- with angular you define the view and the behavior
1
Just to give a quick and easiest example using jQuery:
<span id="main"></span>
<button onclick="add();">Click Me</button>
function add(){
$("#main").html("<h1>Hello</h1>");
}
The <span>
will be populated with <h1>Hello</h1>
on button click
You can run the above example here: http://jsfiddle.net/29mydshx/
2