View Full Version : Resolved Using addClass() function with live()

02-20-2011, 02:54 AM
I am trying to use the .live() jQuery function in cooperation with the .addClass() function, but I am unsure of how exactly to pass the parameter of the class-to-be-added's name through the live() function to work with addClass().

Here is an example of the jQuery I would be using:

$('.mnav').live('click', function() {
I would like to use addClass() in both instances in the code above in cooperation with live() while being able to pass the class's name through the live() function. I've searched around the web quite a bit, but none of my searches have resulted in an answer that fits my specific needs.

I appreciate in advance any help that I may receive.

02-20-2011, 06:50 AM
You could do something like this:

<!DOCTYPE html>
<style type="text/css">
.mnav {
background-color: #f00;

.mnav-over {
background-color: yellow;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript">

$('#xyz').live('click', function(){


<p class="mnav" id="xyz">Click me!</p>


02-20-2011, 05:31 PM
I apologize, but after reevaluating my logic I realized that using click() with live(), as I was already doing, was enough to make addClass() operate as though it was being used with live() itself. The problem arose in my specific case where the CSS background color was not changing due to an external influence.

I was able to resolve the problem without needing an answer to this one. Thank you for your help, though, oVTech.