$('body').append('<div id="mydiv"></div>).addClass('newClass');addClass can be used to add a class to a selector. Take the above example. If the class is added to 'mydiv' instead, not body, this could be handy than writing the two lines:$('body').append('<div id="mydiv"></div>);$('#mydiv').addClass('newClass');
I was looking for a way to have a popup window appear when someone left my page, but not have it appear when they hit the refresh or back buttons on the browser. Since using onUnload="..." in the body tag causes the window to appear when you hit the refresh or back buttons, that didn't do what I wanted.
After doing Google searches for many days I never did find an answer for how to do this. I thought I could have each page open the popup onUnload, but then also have each page close the window onLoad, so the window only stays visible if you actually exit from my whole website. The problem is, I didn't have the handle to the window object in the page that wanted to close the window. I tried passing the handle in a cookie, but that didn't work either.
My solution, which I haven't seen anywhere else before, works like this:
Every page (they are php) includes the same header which has this code in it:
var exit = true; <?php $popstuff = file_get_contents("_popstuff.txt"); $values = explode("|",$popstuff); $usepop = $values[0]; if ($usepop!="on") { echo("exit = false; "); // turn off popup window } ?> function offerWindow() { if ( exit ) { offerPop=window.open('_offer.php', 'offer','width=425,height=298,resizable=0,toolbar= 0,location=0,directories=0,status=0,menubar=0,scro llbars=0'); offerPop.blur(); window.focus(); } } function noExit() { exit = false; } function closeOffer() { offerPop=window.open('_offer.php', 'offer','width=0,height=0,resizable=0,toolbar=0,lo cation=0,directories=0,status=0,menubar=0,scrollba rs=0'); offerPop.close(); } // End --> </script> </head> <body onUnload="offerWindow();" onLoad="closeOffer();">
Now what happens is if you leave the page it opens the popup, but before you even get to see it, the next page closes it (by window name instead of by handle). If you close the browser, or leave the whole web page then the popup remains. If there is a path you wish to take out of the site that does not show the popup then just include onClick="noExit()" to the link and it turns off the popup. Normally the links that go from page to page within the website will all include the "noExit()" call so the popup never even shows up. But the problem where the popup shows up on browser refresh or back buttons just goes away.
There is a line like the following. $(afterButton).removeClass("firstButton").addClass("firstButton"); afterButton element is not null. But this object can not add a new class. Alert to look at the properties by the method of the object is added to a class. Why not work?
that is IE the div #msgsp is not hidden and when focus on the input box #eventname the background color aint changed are there special methods/syntax for IE? are these methods intended to work in IE?
I have a strange problem that occurs in IE 7 and 8 and does not occur in Firefox or Safari.I'm dynamically adding class to a table row on a checkbox selection. A row contains some input fields that get enabled or disabled. If a row is enabled, it gets highlighted using selectedrow class. If it gets disabled, the class is removed:
I want to add a 'visited' class to a table cell and all of it's siblings if the link in the first td has been visited.
Here is my markup.
I've tried his:
And this:
And the class only gets added/appended to the table cells in FF, not webkit or IE and firebug tells me that the css is fine and would be applied if the class were present.
The problem: The addClass does not affect the styling of #title. Firebug shows .error, but as an empty selector. And, BTW, is this an appropriate way to flag errors -- by adding or removing a class?
I'm trying to write a cinema seat selection page and I'm hitting a problem with a selector not recognising a 'booked' class that I've just been added via JSON. I wonder if anyone could tell me why it works ok when I hard code the 'booked' class in but not when I do it through jQuery. Should I just do it in PHP??? or is there a way around the problem.
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: [code]
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 want to add a class to a navigation button, based on the position of my sliding <ul>.
The addClass("not-active") works when the page first loads, but when the <div class="button next"> is clicked, the position changes, and so I want the evaluation of the if statement to change (and thus trigger the addClass("active"). That's not happening. (I realize this would give me both the active and not-active classes -- I'll deal with removeClass later.
I have the usual unordered list for a navigation menu with submenus...
html:
<ul> <li><a href="#">Link 1</a></li> <li>
[code].....
All of the links inside of the parent <li> have a border radius. But if the parent <li> has a child <ul>, I don't want the link to have a radius.I'm currently using this jQuery:
When addClass('choose') to li, there is always a white space right under it. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URl]"> <html xmlns="[URL]"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script type="text/javascript" src="demo_inc/jQuery.js"></script> .....
I'm building a gallery and i have a couple of thumbnails. There is always 1 active thumbnail (opacity 100%) of the showing image and several inactive thumbnails (opacity 50%).
I've build some functions to catch clicks for those functions:
IE8 not knowing how to handle last-child css I am using this globalworkaround, of course with an extra IE css $(document).ready(function() { $("#footer ul li:last-child").addClass("ielast");});
I have a simple navigation with four buttons that I want to apply an .active class to a button when it is clicked, but I also have to remove the class of the current button using the .active class. What is the easiest most efficient method of doing this?
I have a server side include navigation using classic ASP. I tried to use jQuery cookie which I store the id of the link clicked into it in order to asign a class on that link but not on the current page but on the page that the link is pointing!
i have in place an fade in application of addclass to a selector but i would like the transition to use one of the easing plugin equations instead for more dynamism. I can't tell how i would do this, since all the examples only use the animate function.
I want to change the color on every click of the div, by changing theclass and checking if hasClass. First removeClass, then addClass.But this won't work?Live demo:
http://www.edwinistrator.com/stuff/jquery/ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd">
How can I add class to a list and the sub-list...? I have tried the code below but it wont work... Code: $(document).ready(function(){ $("#menu li:last").addClass('last'); $("#menu li li:last").addClass('sublast'); }); This is the html code which I add the class 'last' and 'sublast' manually... the ideal situation I wish to achieve is to add these classes through jquery. Is it possible??
Iam using Raphael and add the same question in their google group too, but they said, its jquery specific. I think, jquery doesnt found my circle. Maybe different id - handling between SVG-specific and plain DOM elements?