首页 \ 问答 \ 我如何在这里使用选择器(How can I use this here with selector)

我如何在这里使用选择器(How can I use this here with selector)

<style>
    .disNone{display:none;}
    .disBlock{display:block;}
</style>

<script>
    $(".visitlink.item span").click(function(){
        $(".summary.item").toggleClass("disNone");
        $(".fullsum.item").toggleClass("disBlock");  
    });
</script>

<div class="wrapper">
    <div class="coursebox">
        <div class="summary item">summary</div>
        <div class="fullsum item">fullsum</div>
        <div class="visitlink item"><span>Readmore</span></div>
    </div>
    <div class="coursebox">
        <div class="summary item">summary</div>
        <div class="fullsum item">fullsum</div>
        <div class="visitlink item"><span>Readmore</span></div>
    </div>
</div>

如何在click div上应用class它正在处理这两个div如何编写代码来定位它。


<style>
    .disNone{display:none;}
    .disBlock{display:block;}
</style>

<script>
    $(".visitlink.item span").click(function(){
        $(".summary.item").toggleClass("disNone");
        $(".fullsum.item").toggleClass("disBlock");  
    });
</script>

<div class="wrapper">
    <div class="coursebox">
        <div class="summary item">summary</div>
        <div class="fullsum item">fullsum</div>
        <div class="visitlink item"><span>Readmore</span></div>
    </div>
    <div class="coursebox">
        <div class="summary item">summary</div>
        <div class="fullsum item">fullsum</div>
        <div class="visitlink item"><span>Readmore</span></div>
    </div>
</div>

How can I apply class on click div it is working on both div how can I write the code to target this.


原文:https://stackoverflow.com/questions/36004717
更新时间:2019-12-03 08:12

最满意答案

你可以改为

 $(this).parent().siblings(".summary.item").toggleClass("disNone");
 $(this).parent().siblings(".fullSum.item").toggleClass("disBlock");

由于被点击的元素是span元素,目标元素是它的父div的兄弟。


You can change to

 $(this).parent().siblings(".summary.item").toggleClass("disNone");
 $(this).parent().siblings(".fullSum.item").toggleClass("disBlock");

As the clicked element is span element and the target elements are the siblings of it's parent div.

2016-03-15

相关问答

更多

在MVP模式中的HTTP请求在哪里?(Where to do HTTP requests in MVP pattern?)

您需要的是从模型到演示者的回调结构。 我通常使用和推荐的是使用RxJava,retrofit2已经有一个返回Observable对象的选项,这使得一切变得更容易。 假设你有一个像这样的端点,这是一个返回一个observable的改进响应: @Headers({"Content-Type: application/json", "Accept: application/json"}) @GET("/api/v1/banners") Observable<Response<GetBannersRes

AutoHotkey忽略完整路径从活动文件夹转到某个文件夹(AutoHotkey go to certain folder from active folder by ignoring full path)

#If WinActive("ahk_class CabinetWClass") ; explorer F1:: for window in ComObjCreate("Shell.Application").Windows try Fullpath := window.Document.Folder.Self.Path ; IfExist, %Fullpath%\1\ Run, %Fullpath%\1 return F2:: for window in ComObjCreate(

透明背景(transparent back ground)

有关各种对象的受支持CSS样式的列表,请参阅此页面 。 我建议使用<div>上的填充和<p>上的对齐将<p>包装在<div> <p> 。 var outputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test1.pdf"); using (var fs = new FileStream(outputFile, FileMode.Create, FileA

使用jQuery更新按钮上的data-attr(Updating data-attr on a button with jQuery)

$(this)指的是返回函数。 使用胖箭头功能或这个self技巧。 $('.follow').click(function () { var id = $(this).data("id"); var action = $(this).data("action"); // Define self to be the .follow element var self = $(this); var url = '/action/' + action; $.aj

使用awk打印最后一个字段然后第一个使用$ NF [复制](Using awk to print the last field then the first using $NF [duplicate])

由于它对我来说工作正常,我怀疑它可能是可能导致此问题的车载字符,如果是这种情况,请尝试以下操作: 1-通过执行以下操作检查任何Input_file中是否存在托架字符: cat -v Input_file 2-如果在Input_file中找到任何托架字符,则可以通过执行以下操作删除它们: tr -d '\r' < Input_file > temp_file && mv temp_file Input_file Since it works fine for me, I am suspe

knockout.js observable没有更新(knockout.js observable is not updating)

将firstName()更改为firstName <p>First Name: <input data-bind="value: firstName" /></p> <p>First Name From span: <span data-bind="text: firstName" ></span> </p> Change firstName() to firstName <p>First Name: <input data-bind="value: firstName" /></p> <

获取表中的数组值(Get Array Value In Table)

<?php foreach ($Array as $key => $value){ ?> <?foreach ($value as $key1 => $value1){?> <?foreach ($value1 as $key2 => $value2){?> <? if ($value2){ ?> <tr class="active">

如何在Android Studio中引用android导航图标?(How to reference android navigation up icon within Android Studio?)

我最终从Google的GitHub获得了Material Icons https://github.com/google/material-design-icons I ended up getting the Material Icons from Google's GitHub https://github.com/google/material-design-icons

相关文章

更多

最新问答

更多
  • 根据Woocommerce中的自定义字段计算自定义购物车商品价格(Custom cart item price calculation based on dimentions custom fields in Woocommerce)
  • 分开foreach项目并单独打印(Separate foreach items and print them individually)
  • 写模式管道是否同步?(Is write mode pipe synchronous?)
  • 发现可用的Windows Phone强调色和本地化名称(Discover available Windows Phone accent colors and localized names)
  • 使用多线程和WPF更新集合(Update Collection with multithreading and WPF)
  • 如何在字符串的情况下使用同步?(How should the synchronization be used in case of strings?)
  • 打印唯一的行,比较不超过N个字符(Print unique lines, compare no more than N characters)
  • Javascript / jQuery - 如何调用switch case从另一个函数执行(Javascript/jQuery - how to call a switch case to execute from another function)
  • Hbase超时错误不断发生(Hbase timeout errors keep occuring)
  • 如何在Delphi中更改TabControl中活动TAB的颜色(How to change the color of active TAB in a TabControl, in Delphi)
  • 正则表达式:在sublime文本中替换一些PHP代码(Regex: replace some pieces of php code in sublime text)
  • 在带有Scene2D的LibGDX中,如何在按下按钮时连续向右走?(In LibGDX with Scene2D, how can I continuously walk to the right when a button is pressed?)
  • 累加器如何在Haskell中工作?(How do accumulators work in Haskell?)
  • 使用开关检查市场和前缀与正确的货币符号(using switch to check market and prefix with correct currency symbol)
  • 在哪里分配一次使用类?(Where to allocate one time use class?)
  • 如何从两个DateTime / NaiveDateTime获取持续时间?(How do I get Duration from two DateTime / NaiveDateTime?)
  • 解析TimeSpan大于24小时?(Parse a TimeSpan greater than 24 hours? [duplicate])
  • 如何在球拍中本地更改阅读规则?(How to locally change reading rules in racket?)
  • 数据库应该由DI注入时的模拟存储(通过构造函数)(Mock storage when database should be injected by DI (through constructor))
  • 使用maven集成2个eclipse项目(Integrate 2 eclipse projects using maven)
  • 角度ng-repeat不检测变化(Angular ng-repeat not detecting changes)
  • Xaml组件在Silverlight + XNA应用程序的多个页面中可见(Xaml component visible in multiple pages in Silverlight+XNA applications)
  • 如何将`var`变量等同于另一个查询(How to equate `var` variable to another query)
  • 如何设计hyperledger链代码以适合您的业务?(how to design your chaincode of hyperledger to fit for your business?)
  • PHP readfile错误(PHP readfile error)
  • 在Date之后排序列表然后是时间(Sorting list after Date then time)
  • Android内部版本号(Android build number)
  • 在没有预设退出条件的情况下停止无限循环(stopping an infinite loop with no preset exit condition)
  • Phonegap应用程序全屏通过html页面中的按钮(Phonegap Application fullscreen through a button in html page)
  • PAA是否适合在门户网站中自动执行wcm库部署和设置?(Is PAA a good candidate for automating wcm library deployment and setup in portal?)