Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7919879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:01:00+00:00 2026-06-03T16:01:00+00:00

I am using jqueryMobile : <div id=header> <h1>conent</h1> </div> now in .js file :

  • 0

I am using jqueryMobile :

 <div id="header"> 
  <h1>conent</h1>
 </div>

now in .js file :

 $("#header").attr("data-role","header");

This not works , but if i did :

 <div id="header" data-role="header"> 
  <h1>conent</h1>
 </div>

It works properly , but why when we are inserting attribute data-role dynamically through jquery it does`nt work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:01:01+00:00Added an answer on June 3, 2026 at 4:01 pm

    What matters here is the time at which you are adding the attribute to the #header div. I would suggest that you bind to the pagebeforecreate event. This way you are adding the attribute before JQM initializes the page. i.e.

    ​$(document).on('pagebeforecreate', function(){
        $("#header").attr("data-role","header");
    });​
    

    Here is a working example http://jsfiddle.net/codaniel/wJdvK/1/

    Here is a quote from docs.

    pagebeforecreate

    Triggered on the page being initialized, before most plugin auto-initialization occurs.

    $( '#aboutPage' ).live( 'pagebeforecreate',function(event){
      alert( 'This page was just inserted into the dom!' );
    });
    

    Note that by binding to pagebeforecreate, you can manipulate markup before jQuery Mobile’s default widgets are auto-initialized. For example, say you want to add data-attributes via JavaScript instead of in the HTML source, this is the event you’d use.

    $( '#aboutPage' ).live( 'pagebeforecreate',function(event){
      // manipulate this page before its widgets are auto-initialized
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to disable the button in coding using jquery mobile? <div data-role=button id=val>Value</div> [Note
I'm using nested pages in Jquery Mobile: Looks like this: // wrap page <div
I am using jQueryMobile 1.1-rc1 and my pageloading indicator is not displaying correctly. I
I’m using a jQuery mobile slider in a JQM dialog but it’s not being
<div data-role=content> <ul data-role=listview data-theme=a data-dividertheme=b> <li data-role=list-divider >Transition Effects</li> <li><a href=#second>Slide</a></li> <li><a href=TestPage1.htm![enter
I'm using the scrollview experimental feature of jQuery Mobile: <div class=carousel data-scroll=xp> ... my
Possible Duplicate JavaScript: Changing src-attribute of a embed-tag but this is not working for
I am using phoneGap and jQuery Mobile . When I use a <div></div> tag
Im using jquerymobile together with codeigniter framework and I'm having a problem I have
I am using jquerymobile in my web application, I have to open html page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.