0

hi

i have two div with same class name.these two div are generated dynamically by javascript from different server, so i dont have access to css file. i want hide one div when page load. so how to acess the div.

regards
rajan

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Airshow
0

I assume that you have to use a
js script for this as php can't affect the divs as they don't exist until after the data has left the server.

You can use jQuery's $('document').ready() to alter the div classes or apply an inline style/css attribute, e.g. style="display:none;" or $('.classname').css("display","none");

Of course, as you'll guess, you have to reference the first or second of the two divs as they have the same class. If they have ids, you could reference them directly like that, e.g. $('#idname').css("display","none");

If not, say it's only the first div:

$(".classname:first").css("display", "none");

or for last:

$(".classname:last").css("display", "none");

You can then use

$(".classname:last").css("display", "");

to show the div - link this to an event, e.g. click.

Anyway, I'm a duffer at js/jQuery, so you may get a better response over at the js forum.

0

In jQuery, you can address the two divs collectively as follows:

$("div.myclassname").hide();

Or individually as follows:

$("div.myclassname").eq(0).hide(); //first div
$("div.myclassname").eq(1).hide(); //second div
//etc.

In these examples, the div(s) are hidden. For some other action, change hide() .

Airshow

Edited by Airshow: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.