0

I am using jQuery Mobile. Currently I am dynamically adding a custom header using javascript to the html file. I would like to add a jQuery mobile header using javascript, by appending it to the DOM. Adding this to the .html code directly is no option.

How could this be done?

2 Answers 2

1

not sure I understand the question. do you mean something like:

<script type="text/javascript">

document.addEventListener('yourevent',function(){
    script = document.createElement('script');
    script.src = 'path/to/your/jquery script src';
    script.type = "text/javascript";
    document.getElementsByTagName('head')[0].appendChild(script);
},false);

</script>
Sign up to request clarification or add additional context in comments.

3 Comments

oops had a type in getElementsByTagName - fixed!
thanks for the idea. I am trying to add a jquery mobile object to the DOM. jQuery mobile adds special css rules/formating to objects when the website is loaded. Adding all the properties is tedious. For instance the list has the function listview() of doing so.
could you refine what exactly do you mean in "jquery mobile object"
0

Answer:

-> Load the js file that has the document ready function for creating the DOM elements before the jquery mobile js. -> Simply change this in the header of the .html file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.