I am developing an application using Asp.net mvc and jquery. I’d like to use the same naming convention (classes and ids) for html elements in different views.
In case when I want to load a partial view asynchronously, the $(document).ready() piece of code in the main view loses its usefulness because none of the patial view’s html tags and css naming is recognized by jquery. I certainly do not want to write the same code for every view. What’s th ebest way to solve this issue?
You can use
.live()for this, for example:Becomes this:
.live()works in a different way..click()binds to the elements the selector matched when it ran, usuallydocument.ready..live()works by living at the DOM root, listening for events to bubble and executing the handler if the event that bubble’s target matches the selector.