...

View Full Version : Load css if specified text not present



ccristian
10-04-2011, 01:29 PM
I'm trying to create/find a script that will do the following:
-load a css file regardless of any conditions.
-do not load the css file if a certain text is present in a specified html div tag.

i know this is done with a if/else state like this:

if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}

but I do not know how to add the condition for the variable text and to specify the css file.

I want the javascript to ignore loading the css if a div tag like this:
<div class="menu-opener"><a class="gwt-Anchor" href="javascript:">Text1<img src=..//img.jpg"></a></div>contains the word Text1, or any other I specify.
Else, if any other text inside the div, the css should load normally.

I believe this is not difficult for a js knower and I would be very grateful for a solution.

Kor
10-04-2011, 02:08 PM
I'm trying to create/find a script that will do the following:
-load a css file regardless of any conditions.
-do not load the css file if a certain text is present in a specified html div tag
AFAIK it is not possible. The CSS file should be loaded within the HEAD section (or at least before any element from BODY is loaded), or any HTML DIV element is placed below the HEAD, in the BODY section. So that you can not turn back to load (or, even less possible, to unload) something in the HEAD following a condition which depends on a value written in the BODY.

After all, your aim sounds illogical to me. Can you detail your problem? Why do you need that? Maybe we could find another approach, as the one you want is impossible.

ccristian
10-04-2011, 05:24 PM
I'm trying to find a simple solution of hiding some information from all the users, except a few selected ones. While loading another css file is not a perfect one, it is sufficient for what i need.
so it should be, in mind, something like:

if (div contains the given text (user name - any of the user names given) )
{
nothing happens
}
else
{
load css
}
poate te pricepi tu (maybe you can find a solution). thank you very much.

sunfighter
10-04-2011, 07:46 PM
Should be able to do this in php.
Since the "if a certain text is present in a specified html div tag" has to be specified in the html you could add a php after the text that calls a function to "include" or not the css file.

Additional:
user name may come from the login and exists in the DB. You can add the include or not to the database.

ie:
query on user name -> Find not_include column -> else include. This makes the css subject to the user name.

poate te pricepi tu => Nice to have Im Translator installed.

Kor
10-05-2011, 09:49 AM
I'm trying to find a simple solution of hiding some information from all the users, except a few selected ones.
That is definitely a job for a server-side code. Which kind of "selected" users? Registered in a DB? Or how?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum