简体   繁体   English

定位从PHP传递的特定元素ID

[英]Targeting specific element ID that is passed from PHP

I am currently listing 10 items per page , and problem is that when this function is called it will only target 1st (latest) element and do nothing on rest of them. 我目前每页列出10个项目,问题是,当调用此函数时,它将仅以第一个(最新)元素为目标,而对其余元素则不执行任何操作。 My question is : How would i target each individual <span id="report-text"></span> with <i id="report"></i> element that belong to same unique-id <div id="$dbstuff></div> given by PHP. 我的问题是:我将如何使用属于同一唯一ID <div id="$dbstuff></div> <i id="report"></i>元素来定位每个<span id="report-text"></span> <div id="$dbstuff></div>由PHP提供。

This is my Jquery code to target element 这是我对目标元素的Jquery代码

$('#report').hover(function(){
    $('#report-text').show();
},function(){
$('#report-text').hide();
});

HTML code is following : HTML代码如下:

<div class="vote_wrap" id="<?php echo $row->id;?>">
<span id="report-text">Report Inappropriate Content</span>
<i class="fa fa-exclamation" id="report"></i>
</div>

You can do it by achieving right selectors .. use class as suggestions in comments .. 您可以通过实现正确的选择器来做到这一点。

Do as below- 做如下-

JS JS

 $('.report').hover(function(){
        $(this).prev('.report-text').show();
    },function(){
    $(this).prev('.report-text').hide();
    });

HTML 的HTML

<div class="vote_wrap" id="<?php echo $row->id;?>">
<span class="report-text">Report Inappropriate Content</span>
<i class="fa fa-exclamation" class="report"></i>
</div>

Each id value must be used only once within a document. 每个id值在文档中只能使用一次。 If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. 如果为多个元素分配了相同的ID,则使用该ID的查询将仅选择DOM中的第一个匹配元素。

Source 资源

Change your ID 's to Class 将您的ID更改为Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM