programing

추가 클래스가 jQuery의 함수가 아닙니다.

telecom 2023. 3. 26. 09:38
반응형

추가 클래스가 jQuery의 함수가 아닙니다.

뷰포트 요소에 클래스를 추가해야 하는 마우스 오버 기능이 있지만 마우스 오버하면 firebug 오류가 나타납니다.TypeError: jQuery(...).addclass는 함수가 아닙니다.

HTML은 다음과 같습니다.

<!DOCTYPE html>
<html>
<head> 
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php wp_title('|','true','right'); ?><?php bloginfo('name'); ?></title>
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url'     ); ?>" />
<?php wp_head(); ?>
</head>
<body <?php body_class($class); ?>>
<header>
<div class="main-logo">
    <div id="site-title">

    </div><!--.site-title-->
</div><!--main-logo-->

<div class="header-right">
</div><!--header-right-->
</header>

<nav class="main">
<?php wp_nav_menu( array( 'theme_location' => 'main-menu' ) ); ?>
</nav>

<div class="viewport">
<script type="text/javascript"><!--//--><![CDATA[//><!--
jQuery(document).ready(function(jQuery){
jQuery('nav .home a').mouseover(function()
  {
    jQuery('.viewport').addclass('.viewporthome');
  });
});
 //--><!]]></script>
</div>
</div>

관련 스타일은 다음과 같습니다.

    .viewport
    {
height: 400px;
width: 400px;
position: relative;
top: -90px;
margin: 0 auto;

}

.viewporthome
{
background-image: url('images/Screen2.png');
background-repeat: no-repeat;
background-position: center;
background-attachment: relative;

}

JS 파일은 다음과 같습니다.

      var hoverhome = 'url("images/Screen2.png")';
  var empty = '';
  var success = 'SUCCESS!';
  //home
  jQuery('nav .home a').hover(function()
  {
    jQuery('.viewport').css('background-image', hoverhome);

  });
  jQuery('nav .home a').mouseout(function()
  {    
        jQuery('.viewport').css('background-image', empty);
  }); 

다음을 시도해 보십시오.

jQuery('.viewport').addClass('viewporthome');

addClass대문자 "C"가 필요합니다.

또한 클래스를 추가할 때 문자열에 "."를 넣을 필요가 없습니다.그렇지 않으면 클래스는..viewporthome.

대신 사용addclass

클래스 추가:

$(".something").click(function(){
    $(this).addClass("style");
});

클래스 삭제:

$(".something").click(function(){
    $(this).removeClass("style");
});

추가 도트 제거 후 사용addClass()addclass()가 아닙니다.

jQuery('.viewport').addClass('viewporthome');

대문자를 확인하십시오.addClass 메서드는 대문자 'C'를 사용합니다.

jQuery addClass 메서드

이미지가 아직 표시되지 않으면 이미지에 대한 상대적인 경로에 문제가 있을 수 있습니다.이미지 폴더가 Javascript 파일과 같은 디렉토리에 없는 경우 경로를 수정해야 할 수 있습니다.디렉토리 구조를 모르면 무엇을 해야 하는지 정확히 말할 수 없습니다.

언급URL : https://stackoverflow.com/questions/16865435/addclass-is-not-a-function-in-jquery

반응형