Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How we can call class of .css file from our .js file
Before attechment


CSS
.dev
        {
            background-image: url(../Style/Images/valid.png);
            background-position: right center;
            background-repeat: no-repeat;
        }
        .ashish
        {
            background-image: url(../Style/Images/invalid.png);
            background-position: right center;
            background-repeat: no-repeat;
        }


JavaScript
$(function () {

    $('input[type=text]').each(function () {
        var txt = $(this);
        if (txt.val() != null && txt.val() != '') {
            $(this).removeClass('ashish');
            $(this).addClass('dev');
        }
        else {
            $(this).removeClass('dev');
            $(this).addClass('ashish');
        }
    })
    $('input[type=text]').focus(function () {
        var txt = $(this);
        if (txt.val() != null && txt.val() != '') {
            $(this).removeClass('ashish');
            $(this).addClass('dev');
        }
        else {
            $(this).removeClass('dev');
            $(this).addClass('ashish');
        }
    })
    $('input[type=text]').keyup(function () {
        var txt = $(this);
        if (txt.val() != null && txt.val() != '') {

            $(this).removeClass('ashish');
            $(this).addClass('dev');
        }
        else {
            $(this).removeClass('dev');
            $(this).addClass('ashish');
        }
    })


});


When i m coding this only on .aspx page then its working properly...but when i m creating .js & .css file for using this throught my project then my .js file cant load the .css class like(.dev and .ashish)
Posted
Updated 21-May-14 23:33pm
v2
Comments
Kornfeld Eliyahu Peter 22-May-14 5:35am    
How you link your js and css to the html file?
KaushalJB 22-May-14 5:38am    
Did you link your css and js file ?

like
css : <link href="../sites/KTest/Test.css" rel="stylesheet" />
js : <script type="text/javascript" src="../js/jTest.js"></script>

Add .js file and .css file reference in your aspx page.add under head part.


Example:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
//Drag and drop your js and css file.
<link rel="stylesheet" type="text/css" href="yourcssfilename.css" />
    <script type="text/javascript" src="yourjsfilename.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>
 
Share this answer
 
Actually i have not change the image path according to .css and .js file location so after correcting it my code work properly.....thanks for u all 4 ur reply's
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900