遍历jquery对象的代码分享

代码如下:

$("dd").bind("click",function(e){
var $obj = $(e.target);
var i=0;
for (var x in $obj){
i++;
var $hr=(i%5==0) ? "<hr />" : " ";
document.write(x+" "+$hr);
}
});

遍历结果:
0 length prevObject context selector
--------------------------------------------------------------------------------
constructor init jquery size toArray
--------------------------------------------------------------------------------
get pushStack each ready eq
--------------------------------------------------------------------------------
first last slice map end
--------------------------------------------------------------------------------
push sort splice extend data
--------------------------------------------------------------------------------
removeData queue dequeue delay clearQueue
--------------------------------------------------------------------------------
promise attr removeAttr prop removeProp
--------------------------------------------------------------------------------
addClass removeClass toggleClass hasClass val
--------------------------------------------------------------------------------
bind one unbind delegate undelegate
--------------------------------------------------------------------------------
trigger triggerHandler toggle hover live
--------------------------------------------------------------------------------
die blur focus focusin focusout
--------------------------------------------------------------------------------
load resize scroll unload click
--------------------------------------------------------------------------------
dblclick mousedown mouseup mousemove mouseover
--------------------------------------------------------------------------------
mouseout mouseenter mouseleave change select
--------------------------------------------------------------------------------
submit keydown keypress keyup error
--------------------------------------------------------------------------------
find has not filter is
--------------------------------------------------------------------------------
closest index add andSelf parent
--------------------------------------------------------------------------------
parents parentsUntil next prev nextAll
--------------------------------------------------------------------------------
prevAll nextUntil prevUntil siblings children
--------------------------------------------------------------------------------
contents text wrapAll wrapInner wrap
--------------------------------------------------------------------------------
unwrap append prepend before after
--------------------------------------------------------------------------------
remove empty clone html replaceWith
--------------------------------------------------------------------------------
detach domManip appendTo prependTo insertBefore
--------------------------------------------------------------------------------
insertAfter replaceAll css serialize serializeArray
--------------------------------------------------------------------------------
ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess
--------------------------------------------------------------------------------
ajaxSend show hide _toggle fadeTo
--------------------------------------------------------------------------------
animate stop slideDown slideUp slideToggle
--------------------------------------------------------------------------------
fadeIn fadeOut fadeToggle offset position
--------------------------------------------------------------------------------
offsetParent scrollLeft scrollTop innerHeight outerHeight
--------------------------------------------------------------------------------
height innerWidth outerWidth width
再遍历:


代码如下:

$("dd").bind("click",function(e){
var $obj = $(e.target);
var i=0;
for (var x in $obj[0]){
i++;
var $hr=(i%5==0) ? "<hr />" : " ";
document.write(x+" "+$hr);
}
});

遍历结果:
querySelector querySelectorAll scrollTop scrollLeft scrollHeight
--------------------------------------------------------------------------------
scrollWidth clientTop clientLeft clientHeight clientWidth
--------------------------------------------------------------------------------
firstElementChild lastElementChild previousElementSibling nextElementSibling childElementCount
--------------------------------------------------------------------------------
children classList setCapture getElementsByClassName getClientRects
--------------------------------------------------------------------------------
getBoundingClientRect releaseCapture mozMatchesSelector addEventListener removeEventListener
--------------------------------------------------------------------------------
dispatchEvent style contentEditable isContentEditable offsetParent
--------------------------------------------------------------------------------
innerHTML offsetLeft offsetTop offsetHeight offsetWidth
--------------------------------------------------------------------------------
scrollIntoView id title lang dir
--------------------------------------------------------------------------------
className accessKey blur focus click
--------------------------------------------------------------------------------
tagName removeAttributeNS removeAttribute getAttribute getElementsByTagName
--------------------------------------------------------------------------------
setAttribute getElementsByTagNameNS hasAttributeNS setAttributeNS hasAttribute
--------------------------------------------------------------------------------
getAttributeNS nodeName nodeValue nodeType parentNode
--------------------------------------------------------------------------------
childNodes firstChild lastChild previousSibling nextSibling
--------------------------------------------------------------------------------
attributes ownerDocument namespaceURI prefix localName
--------------------------------------------------------------------------------
baseURI textContent setUserData getUserData insertBefore
--------------------------------------------------------------------------------
replaceChild removeChild appendChild hasChildNodes cloneNode
--------------------------------------------------------------------------------
normalize isSupported hasAttributes compareDocumentPosition isSameNode
--------------------------------------------------------------------------------
lookupPrefix isDefaultNamespace lookupNamespaceURI isEqualNode getAttributeNode
--------------------------------------------------------------------------------
setAttributeNode removeAttributeNode getAttributeNodeNS setAttributeNodeNS ELEMENT_NODE
--------------------------------------------------------------------------------
ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE
--------------------------------------------------------------------------------
PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE
--------------------------------------------------------------------------------
NOTATION_NODE DOCUMENT_POSITION_DISCONNECTED DOCUMENT_POSITION_PRECEDING DOCUMENT_POSITION_FOLLOWING DOCUMENT_POSITION_CONTAINS
--------------------------------------------------------------------------------
DOCUMENT_POSITION_CONTAINED_BY DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC hidden tabIndex draggable
--------------------------------------------------------------------------------
spellcheck dataset
于是用$("dd")[0].tagName 可以获得tagName.
参考:http://www.mkyong.com/jquery/jquery-how-to-get-the-tag-name/
然后与$("a")遍历的结果对比


代码如下:

$("a").bind("click",function(e){
var $obj = $(e.target);
var i=0;
for (var x in $obj){
i++;
var $hr=(i%5==0) ? "<hr />" : " ";
document.write(x+" "+$hr);
}
});

遍历结果:
0 context length constructor init
--------------------------------------------------------------------------------
selector jquery size toArray get
--------------------------------------------------------------------------------
pushStack each ready eq first
--------------------------------------------------------------------------------
last slice map end push
--------------------------------------------------------------------------------
sort splice extend data removeData
--------------------------------------------------------------------------------
queue dequeue delay clearQueue promise
--------------------------------------------------------------------------------
attr removeAttr prop removeProp addClass
--------------------------------------------------------------------------------
removeClass toggleClass hasClass val bind
--------------------------------------------------------------------------------
one unbind delegate undelegate trigger
--------------------------------------------------------------------------------
triggerHandler toggle hover live die
--------------------------------------------------------------------------------
blur focus focusin focusout load
--------------------------------------------------------------------------------
resize scroll unload click dblclick
--------------------------------------------------------------------------------
mousedown mouseup mousemove mouseover mouseout
--------------------------------------------------------------------------------
mouseenter mouseleave change select submit
--------------------------------------------------------------------------------
keydown keypress keyup error find
--------------------------------------------------------------------------------
has not filter is closest
--------------------------------------------------------------------------------
index add andSelf parent parents
--------------------------------------------------------------------------------
parentsUntil next prev nextAll prevAll
--------------------------------------------------------------------------------
nextUntil prevUntil siblings children contents
--------------------------------------------------------------------------------
text wrapAll wrapInner wrap unwrap
--------------------------------------------------------------------------------
append prepend before after remove
--------------------------------------------------------------------------------
empty clone html replaceWith detach
--------------------------------------------------------------------------------
domManip appendTo prependTo insertBefore insertAfter
--------------------------------------------------------------------------------
replaceAll css serialize serializeArray ajaxStart
--------------------------------------------------------------------------------
ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend
--------------------------------------------------------------------------------
show hide _toggle fadeTo animate
--------------------------------------------------------------------------------
stop slideDown slideUp slideToggle fadeIn
--------------------------------------------------------------------------------
fadeOut fadeToggle offset position offsetParent
--------------------------------------------------------------------------------
scrollLeft scrollTop innerHeight outerHeight height
--------------------------------------------------------------------------------
innerWidth outerWidth width

再遍历:


代码如下:

$("a").bind("click",function(e){
var $obj = $(e.target);
var i=0;
for (var x in $obj[0]){
i++;
var $hr=(i%5==0) ? "<hr />" : " ";
document.write(x+" "+$hr);
}
});

遍历结果:
jQuery16407028609993839658 querySelector querySelectorAll scrollTop scrollLeft
--------------------------------------------------------------------------------
scrollHeight scrollWidth clientTop clientLeft clientHeight
--------------------------------------------------------------------------------
clientWidth firstElementChild lastElementChild previousElementSibling nextElementSibling
--------------------------------------------------------------------------------
childElementCount children classList setCapture getElementsByClassName
--------------------------------------------------------------------------------
getClientRects getBoundingClientRect releaseCapture mozMatchesSelector addEventListener
--------------------------------------------------------------------------------
removeEventListener dispatchEvent style contentEditable isContentEditable
--------------------------------------------------------------------------------
offsetParent innerHTML offsetLeft offsetTop offsetHeight
--------------------------------------------------------------------------------
offsetWidth scrollIntoView href rel target
--------------------------------------------------------------------------------
name text search hash id
--------------------------------------------------------------------------------
title lang dir className accessKey
--------------------------------------------------------------------------------
blur focus click tagName removeAttributeNS
--------------------------------------------------------------------------------
removeAttribute getAttribute getElementsByTagName setAttribute getElementsByTagNameNS
--------------------------------------------------------------------------------
hasAttributeNS setAttributeNS hasAttribute getAttributeNS nodeName
--------------------------------------------------------------------------------
nodeValue nodeType parentNode childNodes firstChild
--------------------------------------------------------------------------------
lastChild previousSibling nextSibling attributes ownerDocument
--------------------------------------------------------------------------------
namespaceURI prefix localName baseURI textContent
--------------------------------------------------------------------------------
setUserData getUserData insertBefore replaceChild removeChild
--------------------------------------------------------------------------------
appendChild hasChildNodes cloneNode normalize isSupported
--------------------------------------------------------------------------------
hasAttributes compareDocumentPosition isSameNode lookupPrefix isDefaultNamespace
--------------------------------------------------------------------------------
lookupNamespaceURI isEqualNode tabIndex ELEMENT_NODE ATTRIBUTE_NODE
--------------------------------------------------------------------------------
TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE
--------------------------------------------------------------------------------
COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE
--------------------------------------------------------------------------------
DOCUMENT_POSITION_DISCONNECTED DOCUMENT_POSITION_PRECEDING DOCUMENT_POSITION_FOLLOWING DOCUMENT_POSITION_CONTAINS DOCUMENT_POSITION_CONTAINED_BY
--------------------------------------------------------------------------------
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC getAttributeNode setAttributeNode removeAttributeNode getAttributeNodeNS
--------------------------------------------------------------------------------
setAttributeNodeNS ping hreflang type protocol
--------------------------------------------------------------------------------
host hostname port pathname charset
--------------------------------------------------------------------------------
coords rev shape hidden draggable
--------------------------------------------------------------------------------
spellcheck dataset
jQuery Get Tag Name


代码如下:

<html>
<head>
<title>jQuery Get Tag Name</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){

var $tag = $('p')[0].tagName; //'P'
alert($tag);

var $tag = $('.classTag1')[0].tagName; //'DIV'
alert($tag);

var $tag = $('#idTag1')[0].tagName; //'DIV'
alert($tag);

var $tag = $('p').get(0).tagName; //'P'
alert($tag);

var $tag = $('.classTag1').get(0).tagName; //'DIV'
alert($tag);

var $tag = $('#idTag1').get(0).tagName; //'DIV'
alert($tag);

});
</script>
<body>
<h1>jQuery Get Tag Name</h1>
<p>
This is paragrah 1
</p>

<div class="classTag1">
This is class='classTag1'
</div>

<div id="idTag1">
This is id='idTag1'
</div>
</body>
</html>

(0)

相关推荐

  • 遍历jquery对象的代码分享

    复制代码 代码如下: $("dd").bind("click",function(e){ var $obj = $(e.target); var i=0; for (var x in $obj){ i++; var $hr=(i%5==0) ? "<hr />" : " "; document.write(x+" "+$hr); } }); 遍历结果: 0 length prevObject c

  • jQuery 动画效果代码分享

    一.显示.隐藏 jQuery 中显示方法为:.show(),隐藏方法为:.hide().在无参数的时候,只是硬性的显示内容和隐藏内容. $('.show').click(function(){ //设置个触发事件 $('#box').show(); //显示 }); $('.hide').click(function(){ //设置个触发事件 $('#box').hide(); //隐藏 }); 在.show()和.hide()方法可以传递一个参数,这个参数以毫秒(1000 毫秒等于 1 秒钟)

  • Jquery幻灯片特效代码分享--鼠标点击按钮时切换(1)

    本文实例讲述了jQuery实现时尚漂亮的幻灯片特效,基本能满足你在网页上使用幻灯片(焦点图)效果.分享给大家供大家参考.具体如下: 幻灯片效果描述:用鼠标点击右下角数字按钮幻灯片进行左右切换进行切换.   运行效果截图如下: 具体实现代码: <head> <title>Jquery幻灯片焦点图插件</title> <script src="js/jquery-1.4a2.min.js" type="text/javascript&qu

  • 时钟Jquery+html5特效代码分享(可设置闹钟并且语音提醒)

    本文实例讲述了Jquery+html5可设置闹钟并且会语音提醒的时钟特效.分享给大家供大家参考.具体如下: 这是一款基于Jquery+html5实现可设置闹钟并且会语音提醒的时钟特效代码,超逼真的模拟时钟,最大的特点还可以语音提醒,感兴趣的小伙伴们快来研究研究. 运行效果图:-------------------查看效果 下载源码------------------- 小提示:浏览器中如果不能正常运行,可以尝试切换浏览模式. 为大家分享的Jquery+html5实现可设置闹钟并且会语音提醒的时钟

  • Unity3D动态对象优化代码分享

    具体解释请仔细看注释里已经讲解的很细致了,这里就不多废话了 复制代码 代码如下: using UnityEngine; using System.Collections; using System.Collections.Generic; /// <summary> /// 动态对象优化 /// </summary> public class DynamicOptimization : MonoBehaviour {     // Use this for initializati

  • Asp遍历服务器对象的代码

    复制代码 代码如下: 一 遍历Request 方式1: <% For Each r In Request.QueryString  Response.Write "Request("""&r&""") = " & Request(r)  Response.Write "<p>" Next %> 方式2: <% For i = 1 To Request.Q

  • Jquery幻灯片特效代码分享--鼠标滑过按钮时切换(2)

    这篇文章主要介绍了jQuery实现幻灯片焦点图,可实现非常炫目时尚的幻灯片效果,非常具有实用价值,基本能满足你在网页上使用幻灯片(焦点图)效果,具体如下 幻灯片效果描述:用鼠标滑过右下角数字按钮幻灯片进行左右切换进行切换. 自定义切换参数效果:向下切换.切换时间为8秒.鼠标滑过按钮时切换   运行效果截图如下: 具体代码如下 <head> <title>Jquery幻灯片焦点图插件</title> <script src="js/jquery-1.4a2

  • Jquery幻灯片特效代码分享--打开页面随机选择切换方式(3)

    这篇文章主要介绍了jQuery实现幻灯片焦点图,可实现非常炫目时尚的幻灯片效果,非常具有实用价值,基本能满足你在网页上使用幻灯片(焦点图)效果,需要的朋友可以参考下 幻灯片效果描述:与前两节不同的是,这款特效可以打开页面随机选择切换方式(方向)   运行效果截图如下: 具体代码如下 <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <

  • jQuery 阴影插件代码分享

    XP下 FF/遨游3/IE8/IE6(IETester)中的效果 使用方法: 1.先引用jquery,然后引用jquery.textshadow.js(点击下载) 2.给元素加个"text-shadow:x偏移 y偏移 模糊半径 阴影颜色;"的样式(必须,因为插件里面会去找这个样式) 3.给元素应用jquery插件. 4.OK. 复制代码 代码如下: <!DOCTYPE HTML> <html lang="zh-CN"> <head&g

  • jQuery提示效果代码分享

    代码一: 复制代码 代码如下: <p><a href="#" class="tooltip" title="这是我的超链接提示1.">提示1.</a></p> <p><a href="#" class="tooltip" title="这是我的超链接提示2.">提示2.</a></p> <

随机推荐