简体   繁体   English

如何在外部javascript链接的同一类div中添加ID?

[英]How to add an ID in a same class of div in a external javascript link?

I have a javascript link in my html, which is coming from third party. 我的html中有一个javascript链接,该链接来自第三方。 I can't edit the html inside the javascript link directly, but can edit, delete or add using CSS, Javascirpt or Jquery. 我无法直接在javascript链接中编辑html,但可以使用CSS,Javascirpt或Jquery进行编辑,删除或添加。

The javascript link is: javascript链接是:

<div class="fluid-container" style="margin-top:10px;">
        <div class="fluid-container-info">          
            <script src="https://worldtravelink.com/client.ijs?userId=2&amp;resultPage=https://www.ezeerooms.in/m/result.html&amp;state=payment&amp;currency=INR&amp;ver=1.0&amp;confirmPage=https://www.ezeerooms.in/m/confirm.html" type="text/javascript"></script>
        </div>        
    </div>

I found the following html code inside the javascript link by using Firebug. 我使用Firebug在javascript链接中找到了以下html代码。 I have deleted and edited some lengthy part of this html. 我已经删除并编辑了该html的冗长部分。

<div class="wrapper_RightZone">
    <div class="PackageInfoBox">
        <div class="hotel_Package_info_Price">
            <div class="Price_Box">               
                <div class="Price">
                    <font class="PriceElement">23285.33</font>
                    <font class="CurencyElement">INR</font>
                </div>               
            </div>
        </div>       
    </div>   
    <div class="payment-title">
        <div class="StrongClass PaymentDetailsTitle"><button>Payment details</button></div>
    </div>   
    <div class="PackageInfoBox">
        <div class="RoomType_PriceRow">               
            <div class="Cel1Right">Content</div>
        </div>       
        <div class="gm_wrapper">
            <div>
                <div class="subpayment-title">               
                    <div class="StrongClass PaymentOptionTitle"><button>Payment options</button></div>                 
                </div>
                <div class="PackageInfoBox">
                    <div class="Payment_OptionsBox">
                        <div class="pay_credit" id="pay_credit">Content</div>
                    </div>    
                </div>                  
            </div>
        </div> 
    </div>
</div>

I have made some modification by CSS and Javascript. 我已经通过CSS和Javascript进行了一些修改。 I want to toggle PackageInfoBox DIV (class="PackageInfoBox"), when I will click on 'subpayment-title' DIV. 我要切换PackageInfoBox DIV(class =“ PackageInfoBox”),然后单击“ subpayment-title” DIV。 But problem is same class name ie, PackageInfoBox. 但是问题是同一个类名,即PackageInfoBox。 There are four PackageInfoBox class, so it is not possible to identify the last PackageInfoBox DIV, which I want to toggle. 有四个PackageInfoBox类,因此无法标识我要切换的最后一个PackageInfoBox DIV。 So I have used this jquery function to add an ID in the last PackageInfoBox DIV. 因此,我已使用此jquery函数在最后一个PackageInfoBox DIV中添加ID。

<script type="text/javascript">
$(document).ready(function() {
     $(".gm_wrapper .PackageInfoBox").attr("id","SomeID");
});
</script>

And used this jquery function to toggle the PackageInfoBox DIV. 并使用此jquery函数来切换PackageInfoBox DIV。

<script>
$(".subpayment-title").click(function(){
  $("#SomeID").toggle();
});
</script>

But its not working, and not created ID (SomeID) in last PackageInfoBox DIV. 但是它不起作用,并且在最后一个PackageInfoBox DIV中未创建ID(SomeID)。

Anyone can help me? 有人可以帮助我吗?

just use this code if you want your last element of PackageInfoBox 如果您要PackageInfoBox的最后一个元素,请使用此代码

<script type="text/javascript">
    $(document).ready(function() {
         $(".PaymentOptionTitle").on('click',function(){
            $(this).closest('.subpayment-title').next().next().slideToggle();
         });
    });
   </script>

DEMO DEMO

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

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