3

I have an MVC 2 project, consisting of a MasterPageView a child View called Index and a number of PartialViews. The PartialViews are loaded into the Index View using the jQuery Ajax method $.get(....).

My problem is that I am styling the buttons using jQuery UI like:

$('button').button();

but I find that I need to do this on every PartialView. What I would like to do is define this once in the MasterPageView, but if I do this the styling is lost. I'm guessing this is because the styling is applied before the DOM is loaded, is this correct? Is there any way to implement this i.e. just define it on the MasterPageView?

Thanks for the help !

1
  • Is there a reason you need to style them using jQuery? Why not just have a CSS selector that styles all the buttons? Commented Aug 9, 2010 at 22:49

1 Answer 1

2

This wont work when objects are added to the DOM after the initial load. In those cases you should go for the new .live() syntax in jQuery :

$("button").live("load", function(){
    $(this).button();
});

It listens for new objects being added to the DOM and attaches an eventhandler to it..

Hope that helps!

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Yngve, thanks for the reply. I tried this but it didn't work. I placed this in the MasterViewPage but when I loaded my PartialView there was no styling.

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.