Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move button into Div

I need to move this new button into this DIV that already exists. This seems to me like it should work but doesn't. What am I doing wrong?

Button button5 = new Button();
button5.Text = "Five";
button5.CssClass = "buttonCSS";
button5.Click += new EventHandler(button5_Click);
button5.ID = "button5";
this.Controls.Add(button5);               

string myscript = @"      
    var navFooter = document.getElementById('NavFooter');
    var button5 = document.getElementById('button5');
    navFooter.Controls.Add(button5);
    ";
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myscript, true);

I know the two objects are being found. Any ideas?

(Note: I cannot use jQuery.)

Thank you.

like image 954
user390480 Avatar asked Nov 04 '22 15:11

user390480


1 Answers

Controls.Add() is C#, not JavaScript. To append an element to another element with JavaScript, use appendChild():

navFooter.appendChild(button5);
like image 163
James Hill Avatar answered Nov 15 '22 01:11

James Hill