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 9177703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:23:10+00:00 2026-06-17T17:23:10+00:00

I have a home button in the headers with this standard code at many

  • 0

I have a “home” button in the headers with this “standard” code at many places:

<a href="#home" 
    data-role="button" 
    data-iconpos="right"
    data-icon="home" 
   class="ui-btn-right">
   home</a>

I want to render it from a single piece of javascript code since it appears many times in index.html – to decrease code redundancy and for easier changes. (I want to use jQuery so the cross browser functionality is ok)

The code bellow should 🙂 work, what am I doing wrong ?

(I tried to solve it from different angles, I can write out text, put out other html etc. – but I can not tackle data-* and standard html attr together)

THE CODE:

in index.html:

<div  data-role="header">
    <a data-myButton="headerHome> </a>
</div>

in main.js :

$( function () {    
    // put home button into the headers:        
    $("a[data-mybutton = 'headerHome']").( function () {
        $(this).href = "#home";             
        $(this).data("role","button");
        $(this).data("iconpos","right");
        $(this).data("icon","home");
        $(this).class("ui-btn-right");      
    })
})

I call main.js as a last js file in my index.html

  • 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-17T17:23:12+00:00Added an answer on June 17, 2026 at 5:23 pm

    In jQuery Mobile it is not enough just to set the attributes. Correct page event needs to be used, also .button( function needs to be called to restyle the button correctly, like this:

    $('#index').live('pagebeforeshow',function(e,data){    
        $("a[data-mybutton = 'headerHome']")
            .attr("href","#home")
            .data("role","button")
            .data("iconpos","right")
            .data("icon","home")
            .attr("class","ui-btn-right");  
        $("a[data-mybutton = 'headerHome']").button();
    });
    

    Here’s a working example: http://jsfiddle.net/Gajotres/heSKu/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code for my mobilesite: <div data-role=page id=home> <div data-role=header> <h1>home</h1> </div><!--
I have various pages in html like this <body onload=init()> <div data-role=page id=home> <div
when i preess home button there are so many icons are there .i have
I have the following code: @{ ViewBag.Title = Index; } <h2> Index</h2> <div data-role=page>
I have this code: <!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href=@Url.Content(~/Content/Site.css) rel=stylesheet type=text/css />
I want all of my (data-role=button)'s to have a theme of ( data-theme=b )
Guys I have an activity which has a home button, when the button is
I have an app that crashes if i press the home button, back button
We have a file manager-like application where we use the action bar home button
I want to finish the Activity on Home Button Click . I have below

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.