简体   繁体   English

jQuery JavaScript等效

[英]jquery javascript equivalent

I use too much jquery 我使用太多的jQuery

I want to do this with out jquery: 我想用没有jQuery做到这一点:

<a onclick="javascript:$(this).next().css('display', 'none')">

I thought it was this: 我以为是这样的:

<a onclick="javascript:this.nextSibling.style.display = 'none'">

But its not. 但事实并非如此。 Style returns undefined. 样式返回未定义。

Let me clarify: 让我澄清一下:

I want to do this: 我想做这个:

<a class="errorToggle">error</a>
<div style="padding-left:20px;margin:0 0 10px 0;display:none;">

<h4>A PHP Error was encountered</h4>

<p>Severity: <?php echo $severity; ?></p>
<p>Message:  <?php echo $message; ?></p>
<p>Filename: <?php echo $filepath; ?></p>
<p>Line Number: <?php echo $line; ?></p>

</div>

<script type="text/javascript">
  $(".errorToggle").click(function(){
    $(this).next().css("display", "block");
  });
</script>

Without jQuery BECAUSE this is a code igniter error view file that quite often will load before my header does, so I will not have access to jquery. 如果没有jQuery,这是一个代码点火器错误视图文件,通常会在我的标头加载之前加载它,因此我将无法访问jquery。 It doesn't need to be pretty, or well coded, just work. 它不需要漂亮或编码良好,就可以工作。 This will not be used in production. 这将不会在生产中使用。

Take a look at this article: 看一下这篇文章:
JavaScript nextSibling and Cross Browser Compatibility JavaScript nextSibling和跨浏览器兼容性

Excerpt: 摘抄:

The problem was that we were referencing the 'nextSibling' of an element in our JS using the onClick event. 问题是我们使用onClick事件引用了JS中元素的'nextSibling'。 In IE this worked great, however in Firefox the 'nextSibling' could be a line break. 在IE中,这很好用,但是在Firefox中,“ nextSibling”可能是换行符。

You might want to iterate through the "nextSibling()" until you hit what you want. 您可能要遍历“ nextSibling()”,直到找到所需的内容。

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

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