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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:16:17+00:00 2026-06-15T06:16:17+00:00

im new to jquery and twitter bootstrap so please forgive the dumb question. I

  • 0

im new to jquery and twitter bootstrap so please forgive the dumb question.

I have an MVC view which setups up a twitter bootstrap modal and this is activated by a link also output within this view.

I want to use data-remote with the modal to load the modal with the contents of an MVC partial view.

I have all of this working nicely.

but what I then wanted to do was be able to access elements (from the partial view) via jquery from the main view, and even though I am sure I have got the selectors right it is not working as expected.

for example I have a href link which I try to assign to the click event, but this does not fire.

however if I move the script so that it is output within the partial view as pulled into the modal-body, then the script does work and the click event is handled.

I would rather not have to have script in the partial view (even if referenced) , I would rather reference one script in the main view.

is there anyway of being able to access the elements that are remotely loaded into the modal-body without having to put the script within the remote partial view?

as an addition, I just mocked up a test where the modal doesn’t use the data-remote and the anchor href was inserted directly within the modal-body, and doing this I am still unable to access this anchor.click event from the main page.
any suggestions much appreciated.

doing more research I have found an answer in the following post
How to set the input value in a modal dialogue?

This seems to suggest the jquery selector should also include .modal-body
so I have changed my selector from the following :

 $("#TestButton").click(function (ev) {
        ev.preventDefault()

        alert('Test Button Clicked'); 
    })

to this

 $(".modal-body #TestButton").click(function (ev) {
        ev.preventDefault()

        alert('Test Button Clicked'); 
    })

and now the click event fires as I had originally expected.

However im now unsure why I need the .modal-body as part of the jquery selector.? Could someone explain this?

  • 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-15T06:16:18+00:00Added an answer on June 15, 2026 at 6:16 am

    You need to wire up the click events to the href’s when the new dynamic content has been loaded into the DOM.

    When the page loads, JQuery will look through the DOM for your $(“#TestButton”) and find nothing as at the time when this happens the dynamic content has yet to be injected.

    There are a couple of ways of handling this… firstly you can delay the wire up of the click events with JQuery until the new content has been injected, or you can use the .live function of JQuery.

    Your code would be:

    $("#TestButton").live('click', function (ev) {
            ev.preventDefault()
    
            alert('Test Button Clicked'); 
        });
    

    Actually… it seems Live has been depreciated as of JQuery 1.7

    it is…

    $("#TestButton").on('click', function (ev) {
                ev.preventDefault()
    
                alert('Test Button Clicked'); 
            });
    

    Hope this helps.

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

Sidebar

Related Questions

I am relatively new to JQuery, so please excuse this question if it seems
I'm trying to use the new bundling feature in MVC 4 with Twitter bootstrap
I read this question: How to use Twitter Bootstrap ScrollSpy to execute a function
I currently have an app that is using a twitter bootstrap modal box. The
I have application that brings response via Ajax and creates 5-20 new jQuery click
new here and new to jQuery. I've searched for an answer to my question/
im new to jquery and javascript.. Here is the code, this is a sample,
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
I can't get javascript to work with Twitter's Bootstrap. I've got this <p> <a
I have a twitter feed and I create a new date obj so I

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.