i have been trying to create a div inside my DOM every time i press the button yet it says appendChild is not a function sorry for the rude code but thats where i am at the moment.
var btn = document.getElementsByTagName('button')[0];
function crtRow(){
var newDiv = document.createElement('div');
newDiv.className = 'row';
document.getElementsByClassName('container').appendChild(newDiv);
document.body.appendChild(container);
}
btn.addEventListener('click', crtRow)
In your example appendChild is trying to be executed with HTML Collection, which it can't. You need to specify index for html collection document.getElementsByClassName('container')[0]
Also, then you will see another error for this line of code document.body.appendChild(container);. That's because you didn't define a variable called as container. It will try to append undefined to the body.
Related
javascript:
...
//I want use page object outside the loded function
var page
exports.loaded =function (args) {
page = args.object;
page.bindingContext = viewModel;
//there is already a 'grid9' element in XML file
var gridLayout = page.getViewById("grid9");
if(gridLayout ) alert("yes");//<============it works
}
if (page.getViewById("grid9")) alert("yes");//<========== got error
I want use page object outside the loaded function.In my mind,page is defined outside the loaded fuction,then the page variable get the real page object in the funtion,so I can use the page object outside the function right now.
But,I got a error of undefined .And ,without the second if statement ,it goes well.
If I met a variable scope mistake or something else?
First problem with your if is that it will execute before loaded function because its outside of functions so its executte immediately at loading of file so either you put that if somewhere to function or try use this to get current page outside of loaded function
var frameModule=require("ui/frame");
var page = frameModule.topmost().currentPage;
but if its still outside exports.foo = function(){} it's not sure that it will page object
I just started using rivets js a couple of days before. So i am studying it. But got stuck myself
I have created a fiddle here
What i want to do is. I want to remove the data from the div and put another set of data's inside that
So at first the binding is working. But second time when i empty the div and once again bind Its not working
Created Fiddle
http://fiddle.jshell.net/m8j4ycj1/
function render() {
rivets.bind($("#hello"), datas);
return this;
}
rivets.bind($("#hello"), data);
setTimeout(function(){
debugger;
$("#hello").empty();
render();
},1000)
In this code the first binding is working but not after the setTimeout
as i understand you just want to empty the div?
so try to emtpy the model.
if data is:
data = { username: '12345' };
do
data.username = '';
and the view should be updated automatically
greez
I'd love to get my hands on a templates data context.
Can I do something like this?
'click .newContext': function(event, template) {
var template_parent = template.parent();
var parent_data = template_parent.data;
}
You can use Template.parentData(0), the argument defines how deep you want to go, if you pass none, 0 is the default. Check the documentation on this: http://docs.meteor.com/#/full/template_currentdata
Yeah, if you're trying to get the parent's data context you should be able to use the parentData() method on the Template instance. You probably don't even need that second template parameter.
'click .newContext': function(event) {
var parent_data = Template.parentData();
}
A simple app:
function doGet() {
return(test());
}
function test(){
var smiley = UiApp.createApplication().setTitle("TT Bomgar Feedback");
var textIn = smiley.createTextBox().setName("text");
var textOut = smiley.createLabel().setId("label").setVisible(false);
var button = smiley.createSubmitButton("Submit");
var handler = smiley.createServerHandler("handler");
button.addClickHandler(handler);
smiley.add(button);
smiley.add(textIn);
smiley.add(textOut);
return(smiley);
}
function handler(e){
app = UiApp.getActiveApplication();
var text = e.parameter.text;
app.getElementById("label").setVisible(true).setText(text);
return(app);
}
In the handler function, var text is always undefined. This means that the following is returned:
So, undefined is printed instead of "some text".
I don't understand why though, because I have correctly set the name of the text box element in the test function ...
Any assistance is greatly appreciated.
You need to add a callBackElemnt to the handler so that its value will get passed to the handler function. In normal practice, we just add the top most element containing all other elements. But you can also add all the elements whose value you want to pass.
modified script
var handler = smiley.createServerHandler("handler");
handler.addCallbackElement(textIn);
button.addClickHandler(handler);
You have to add callback element to your server handler:
...
var handler = smiley.createServerHandler("handler");
handler.addCallbackElement(textIn);
button.addClickHandler(handler);
...
https://developers.google.com/apps-script/class_serverhandler#addCallbackElement
thanks so much in advance...here is the problem...
I am trying to add dynamic HTML element (EX. [delete]),everytime on a event call using FBJS.I am able to append the element using following code.
var oldFriendHtml = document.getElementById('friend_container');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").getValue()-1)+2;
numi.value = num;
var newElementId = "new"+num;
var newFriendHTML = document.createElement('div');
newFriendHTML.setId(newElementId);
newFriendHTML.setInnerXTML("HTML TO BE ADDED");
oldFriendHtml.appendChild(newFriendHTML);
The problem I am facing is that FBJS parses out the onClick part (event call ) out from the original HTML added .This stops me in the further activity on the added element .It also removes the styling added in the HTML ..
Regarding onclick being parsed out of setInnerXHTML, you can add the event later by using addEventListener.
Here is some sample:
var my_obj = document.getElementById('test');
// add a new event listener for each type of event you needed to capture
my_obj.addEventListener('click',my_click_func); // in your case is onclick
function my_click_func(evnt){
// some action
}
more details see http://developers.facebook.com/docs/fbjs#events