javascript - How to center a button on a page -


i have following code in button's _postrender function:

myapp.splash.btnsplashok_postrender = function (element, contentitem) {     $(element).find("ui-btn-inner").css({         "padding-left": "0"     });     $(element).css({         "padding-left": "0",         "margin-left": "50%",         "margin-right": "50%"     }); }; 

and result this:

rendered page

the padding-left, margin-left, , margin-right being applied div fine. find("ui-btn-inner") doesn't seem working @ all. , margin tags don't seem taking account width of button in order center of page. missing here?


note: accepted answer works simple case. though @rockmandew's third update provides more powerful alternative wishing more complex placements.

to align button add "transform":"translatex(-50%)"

$(element).css({     "padding-left": "0",     "margin-left": "50%",     "transform":"translatex(-50%)" }); 

Comments