XPath Tutorial-from W3schools.com

xiaoxiao2021-03-06  43

Xpath Is A Set of Syntax Rules for DEFINING PARTS OF A XML Document. XPATH ISLT STANDGE WILL NOTBE ABLE TO CREATE XSLT Documents. Start Learning XPath!

XPath Introduction

XPath Is A Set of Syntax Rules for DEFININININININININININININING.

What is xpath?

XPath is a syntax for defining parts of an XML document XPath uses paths to define XML elements XPath defines a library of standard functions XPath is a major element in XSLT XPath is not written in XML XPath is a W3C Standard

Like Traditional File paths

Xpath Uses Path Expressions To Identify Nodes in An XML Document. Thase Path Expressions You See You Work with a Computer File System:

W3Schools / XPath / Default.asp

XPath Example

Look at this Simple XML Document:

Empire Burlesque </ Title></p> <p><Artist> Bob Dylan </ Artist></p> <p><price> 10.90 </ price></p> <p></ cd></p> <p><cd country = "uk"></p> <p><title> hide your heart </ title></p> <p><Artist> Bonnie Tyler </ artist></p> <p><price> 9.90 </ price></p> <p></ cd></p> <p><cd country = "usa"></p> <p><title> greatest Hits </ Title></p> <p><Artist> Dolly Parton </ Artist></p> <p><price> 9.90 </ price></p> <p></ cd></p> <p></ catalog></p> <p>The XPath Expression Below Selects The Root Element Catalog:</p> <p>/ catalog</p> <p>The XPath Expression Below Selects All The CD Elements of The Catalog Element:</p> <p>/ Catalog / CD</p> <p>The XPath Expression Below Selects All The Price Elements of All The CD Elements of The Catalog Element:</p> <p>/ Catalog / CD / PRICE</p> <p>Note: IF The Path Starts with a slash (/) IT Repesents An Absolute Path To An Element! XPath Defines a Library of Standard Functions</p> <p>XPath Defines a library of standard functions for working with strings, number and boolean expressions.</p> <p>The XPath Expression Below Selects All The CD Elements That Have A Price Element with a value larger Than 10.80:</p> <p>/catalog/cd[Price>10.80]</p> <p>XPath is buy in xslt</p> <p>Xpath Is a Major Element of the xslt standard. Without xpath Knowledge you will not becoments.</p> <p>You can read more about xslt in our xlt tutorial.</p> <p>XPath IS A W3C Standard</p> <p>XPath Was Released AS A W3C Recommendation 16. November 1999 AS A LANGUAGE for Addressing Parts of an XML Document.</p> <p>Xpath Was Designed to be used by xslt, xpointer and other xml paarsing software.</p> <p>You can read more about xml and xsl standards in our w3c tutorial.</p> <p>XPath Syntax</p> <p>Xpath Uses path expression..</p> <p>XML EXAMPLE Document</p> <p>We Well Use this Simple XML Document To Describe The Xpath Syntax:</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><catalog></p> <p><cd country = "usa"></p> <p><title> Empire Burlesque </ Title></p> <p><Artist> Bob Dylan </ Artist></p> <p><price> 10.90 </ price></p> <p></ cd></p> <p><cd country = "uk"></p> <p><title> hide your heart </ title></p> <p><Artist> Bonnie Tyler </ artist></p> <p><price> 9.90 </ price></p> <p></ cd></p> <p><cd country = "usa"></p> <p><title> greatest Hits </ Title></p> <p><Artist> Dolly Parton </ Artist></p> <p><price> 9.90 </ price></p> <p></ cd></p> <p></ catalog></p> <p>Locating nodes</p> <p>XML documents can be represented as a tree view of nodes (very similar to the tree view of folders you can see on your computer) .XPath uses a pattern expression to identify nodes in an XML document. An XPath pattern is a slash-separated list Of Child Element Names That Describe a path through the xml document. The pattern "select" Elements That Match the path.</p> <p>The Following Xpath Expression Selects All The Price Elements of All The CD Elements of The Catalog Element:</p> <p>/ Catalog / CD / PRICE</p> <p>NOTE: IF The Path Starts with a slash (/) IT Repesents An Absolute Path To an Element!</p> <p>NOTE: IF The Path Starts with Two Slashes (//) THEN All Elements in The Document That Fulfill The Criteria Will Be SLECTED (EVEN IFER AT DIFFERENT Levels in the XML Tree)!</p> <p>The Following Xpath Expression Selects All The CD Elements in The Document:</p> <p>// CD</p> <p>Selecting Unknown Elements</p> <p>Wildcards (*) can be used to select unknown XML Elements.</p> <p>The Following Xpath Expression Selects All The child Elements of All The cd Elements of the catalog element:</p> <p>/ catalog / cd / *</p> <p>The Following Xpath Expression Selects All The Price Elements That Are Grandchild Elements of The Catalog Element:</p> <p>/ catalog / * / price</p> <p>The Following XPath Expression Selects All Price Elements Which Have 2 Ancestors:</p> <p>/ * / * / price</p> <p>The Following Xpath Expression Selects All Elements in The Document:</p> <p>// *</p> <p>Selecting Branches</p> <p>.</p> <p>The Following Xpath Expression Selects The First CD CHild Element of the Catalog Element:</p> <p>/ Catalog / CD [1]</p> <p>The Following Xpath Expression Selects The Last Cd Child Element of the Catalog Element (NOTE: THE IS no function named first ():</p> <p>/ Catalog / CD [Last ()]</p> <p>THE FOLLOWING XPATH Expression Selects All The CD Elements of The Catalog Element That Have a Price Element: / Catalog / CD [Price]</p> <p>THE FOLLOWING XPATH Expression Selects All The CD Elements of The Catalog Element That Have A Price Element with a value of 10.90:</p> <p>/catalog/cd[proice=10.90]</p> <p>The Following Xpath Expression Selects All The Price Elements of All The CD Elements of The Catalog Element That Have A Price Element with a value of 10.90:</p> <p>/catalog/cd[proice=10.90]/price</p> <p>Selecting Several Paths</p> <p>.</p> <p>The Following Xpath Expression Selects All The Title and Artist Elements of The CD Element of The Catalog Element:</p> <p>/ catalog / cd / title | / catalog / cd / artist</p> <p>The Following Xpath Expression Selects All The Title and Artist Elements in The Document:</p> <p>// Title | // Artist</p> <p>The Following Xpath Expression Selects All The Title, Artist and Price Elements in the document:</p> <p>// Title | // Artist | // Price</p> <p>THE FOLLOWING XPATH EXPRESSION SELECTS All The Title Elements of The CD Element of the Catalog Element, And All The Artist Elements in The Document:</p> <p>/ catalog / cd / title | // artist</p> <p>Selecting Attributes</p> <p>In xpath all attributes areot specified by the @ prefix.</p> <p>This Xpath Expression Selects All Attributes named Country:</p> <p>@ County</p> <p>This Xpath Expression Selects All CD Elements Which Have An Attribute Named Country:</p> <p>// CD [@country]</p> <p>This Xpath Expression Selects All CD Elements Which Have Any Attribute:</p> <p>// CD [@ *]</p> <p>This Xpath Expression Selects All Cd Elements Which Have An Attribute Named Country with a value of 'UK':</p> <p>// CD [@ country = 'uk']</p> <p>XPath location paths</p> <p>A Location path Expression Results in a node-set.</p> <p>Location path expressiona location path can be absolute or relative.</p> <p>An Absolute Location Path Starts with a slash (/) And a relationive location path does not. In Both Cases The location path consists of one or more location steps, Each Separated by a Slash:</p> <p>An Absolute Location Path: / Step / Step / ... a Relative Location Path: Step / Step / ...</p> <p>The location steps are evaluated in order one at a time, from left to right. Each step is evaluated against the nodes in the current node-set. If the location path is absolute, the current node-set consists of the root node. If THE LOCATION PATH IS Relative, The Current Node-Set Consists in: Location Steps Consist of:</p> <p>an axis (specifies the tree relationship between the nodes selected by the location step and the current node) a node test (specifies the node type and expanded-name of the nodes selected by the location step) zero or more predicates (use expressions to further Refine the set of nodes success by the location step)</p> <p>The Syntax for a location Step is:</p> <p>Axisname :: NodeTest [Predicate]</p> <p>EXAMPLE:</p> <p>Child :: price [price = 9.90]</p> <p>Axes and Node Tests</p> <p>Of the curre.</p> <p>AxisNameDescriptionancestorContains all ancestors (parent, grandparent, etc.) of the current node Note: This axis will always include the root node, unless the current node is the root nodeancestor-or-selfContains the current node plus all its ancestors (parent, grandparent, etc.) attributeContains all attributes of the current nodechildContains all children of the current nodedescendantContains all descendants (children, grandchildren, etc.) of the current node Note: This axis never contains attribute or namespace nodesdescendant-or-selfContains the current node plus all its descendants (children, grandchildren, etc.) followingContains everything in the document after the closing tag of the current nodefollowing-siblingContains all siblings after the current node Note: If the current node is an attribute node or namespace node, this axis will be emptynamespaceContains all NAMESPACE NODES OF THE CURRENT NODEPARENTCONTAINS The Parent of The Current NodeprecedingContains Everything in the document that is before the starting tag of the current nodepreceding-siblingContains all siblings before the current node Note: If the current node is an attribute node or namespace node, this axis will be emptyselfContains the current nodeExamples</p> <p>ExampleResultchild :: cdSelects all cd elements that are children of the current node (if the current node has no cd children, it will select an empty node-set) attribute :: srcSelects the src attribute of the current node (if the current node has no src attribute, it will select an empty node-set) child :: * Selects all child elements of the current nodeattribute :: * Selects all attributes of the current nodechild :: text () Selects the text node children of the current nodechild: : node () Selects all the children of the current nodedescendant :: cdSelects all the cd element descendants of the current nodeancestor :: cdSelects all cd ancestors of the current nodeancestor-or-self :: cdSelects all cd ancestors of the current node and, IF The Current Node Is A CD Element, The Current Node As Wellchild :: * / Child :: Pricents All Price GrandRen of The Current Node / Selects The Document Rootpredicates</p> <p>A Predicate filters a node-set INTO A New Node-set. A Predicate Is Placed Inside Square Brackets ([]).</p> <p>Examples</p> <p>ExampleResultchild :: price [price = 9.90] Selects all price elements that are children of the current node with a price element that equals 9.90child :: cd [position () = 1] Selects the first cd child of the current nodechild :: cd [posient () = last ()] selects the last cd child of the current nodechild :: cd [position () = last () - 1] selects the last but one cd child of the current nodechild :: cd [position " <6] Selects the first five cd children of the current node / descendant :: cd [position () = 7] Selects the seventh cd element in the documentchild :: cd [attribute :: type = "classic"] Selects all cd children Of The Current Node That Have A Type Attribute with Value Classic</p> <p>Location path Abbreviated Syntax</p> <p>Abbreviations Can Be Used When Describing a location path.the Most Important Abbreviation Is That Child :: Can be omitted from a location step.</p> <p>Abbrmeaningexample :: cd @ attribute :: cd [@ type = "classic"] is short forchild :: cd [attribute :: type = "classic]. Self :: node (). /// CDE () / child :: cd :: cd..parent :: node () ../cd is short forparent :: node () / child :: /// descendant-or-self :: node () /// CD is short for / descendant-or-self :: node () / child :: cd</p> <p>Examples</p> <p>ExampleResultcdSelects all the cd elements that are children of the current node * Selects all child elements of the current nodetext () Selects all text node children of the current node @ srcSelects the src attribute of the current node @ * Selects all the attributes of the current nodecd [1] Selects the first cd child of the current nodecd [last ()] Selects the last cd child of the current node * / cdSelects all cd grandchildren of the current node / book / chapter [3] / para [1] Selects the first para of the third chapter of the book // cdSelects all the cd descendants of the document root and thus selects all cd elements in the same document as the current node.Selects the current node.//cdSelects the cd element descendants of the current node..Selects the parent of the current node ../@ srcSelects the src attribute of the parent of the current nodecd [@ type = "classic"] Selects all cd children of the current node that have a type attribute with value classiccd [@ Type = "classic"] [5] Selects the fiffh cd child of there current node has a type attribute with value classiccd [5] [@ type = "classic"] Selects the fifth cd child of the current node if that child has a type attribute with value classiccd [@type and @country] Selects all the that CD Children of The Current Node That Have Both a Type Attribute and a Country AttributexPath Expressions</p> <p>XPath Supports Numeric, Equality, RELATIONAL, AND BOOLEAN Expressions.</p> <p>Numeric Expressions</p> <p>Numeric Expressions Are Used to Perform Arithmetic Operations on Numbers.</p> <p>OperatorDescriptionExampleResult Addition6 410-Subtraction6 - 42 * Multiplication 6 * 424DiviVision8 Div 42Modmodulus (Division Remain) 5 mod 21</p> <p>NOTE: XPATH ALWAYS Converts Each Operand to a Number Before Performing An Arithmetic Expression.equality Expressions</p> <p>Equality Expressions Are Used to Test The Equality Between Two Values.</p> <p>OperatorDescriptionExampleResult = like (equal) price = 9.80 t (if price is 9.80)! = NOT LIKE (NOT Equal) Price! = 9.80false</p> <p>Testing against a node-set</p> <p>If the test value is test for equality against a node-set, The result is true node with a value That matches the test value.</p> <p>IF the test value is test for not equal, the result is true node with a value trueness from the test value.</p> <p>The result is what the node-set can be equally and not equal at the same time !!!</p> <p>RELATIONAL Expressions</p> <p>RELATIONAL Expressions Are Used to Compare Two Values.</p> <p>OperatorDescriptionExampleResult <less trion <9.80false (if Price IS 9.80) <= less> Greater Thaprice> 9.80false> = Greater or equalprice> = 9.80 True</p> <p>NOTE: XPath Always Converts Each Operand to a Number Before Performing The Evaluation.</p> <p>Boolean Expressions</p> <p>Boolean Expressions Are Used to Compare Two Values.</p> <p>OperatorDescriptionExampleresultororPrice = 9.80 or price = 9.70true (if price is 9.80) Andand Price <= 9.80 and price = 9.70false</p> <p>XPath Functions</p> <p>XPath Contains a Function Library for Converting Data.</p> <p>XPath Function Library</p> <p>.</p> <p>Node Set Functions</p> <p>NameDescriptionSyntaxcount () Returns the number of nodes in a node-setnumber = count (node-set) id () Selects elements by their unique IDnode-set = id (value) last () Returns the position number of the last node in the processed node listnumber = last () local-name () Returns the local part of a node. A node usually consists of a prefix, a colon, followed by the local namestring = local-name (node) name () Returns the name of a nodestring = name (node) namespace-uri () Returns the namespace URI of a specified nodeuri = namespace-uri (node) position () Returns the position in the node list of the node that is currently being processednumber = position () String Functions</p> <p>NameDescriptionSyntax & Exampleconcat () Returns the concatenation of all its argumentsstring = concat (val1, val2, ..) Example: concat ( 'The', '', 'XML') Result: 'The XML'contains () Returns true if the second string is contained within the first string, otherwise it returns false bool = contains (val, substr) Example: contains ( 'XML', 'X') Result: truenormalize-space () Removes leading and trailing spaces from a string, and replaces all internal sequences of white with one white spacestring = normalize-space (string) Example: normalize-space ( 'The XML') Result: 'The XML'starts-with () Returns true if the first string starts with the second string , otherwise it returns falsebool = starts-with (string, substr) Example: starts-with ( 'XML', 'X') Result: truestring () Converts the value argument to a stringstring (value) Example: string (314) Result : '314'string-length () Returns the number of character of character of character of character of character of character = string-length (String) EXAMPLE: STRING-Length (' beatles') Result: 7SUBString () Returns a Part of the string in T e string argumentstring = substring (string, start, length) Example: substring ( 'Beatles', 1,4) Result:' Beat'substring-after () Returns the part of the string in the string argument that occurs after the substring in the substr argument string = substring-after (string, substr) Example: substring-after ('12 / 10 ',' / ') Result:' 10'substring-before () Returns the part of the string in the string argument that Occurs Before the subside in Substr Argument String = Substring-Before (String, Substr) EXAMPLE: Substring-Before ('12 / 10 ',' / ') Result:' 12 '</p> <p>translate () Performs a character by character replacement It looks in the value argument for characters contained in string1, and replaces each character for the one in the same position in the string2string = translate (value, string1, string2) Examples:. translate ( ' 12:30 ',' 30 ',' 45 ') Result: '12: 45' Translate ('12: 30 ',' 03 ',' 54 ') Result: '12: 45' Translate ('12: 30 ' , '0123', 'Abcd') Result: 'BC: Da'Number Functions</p> <p>NameDescriptionSyntax & Exampleceiling () Returns the smallest integer that is not less than the number argumentnumber = ceiling (number) Example: ceiling (3.14) Result: 4floor () Returns the largest integer that is not greater than the number argument number = floor (number ) Example: floor (3.14) Result: 3number () Converts the value argument to a number number = number (value) Example: number ( '100') Result: 100round () Rounds the number argument to the nearest integerinteger = round (number EXAMPLE: ROUND (3.14) Result: 3sum () Returns The Total Value of A Set of Numeric Values ​​in a node-setNumber = SUM (NODESET) EXAMPLE: SUM (/ CD / Price)</p> <p>Boolean functions</p> <p>NameDescriptionSyntax & Exampleboolean () Converts the value argument to Boolean and returns true or falsebool = boolean (value) false () Returns falsefalse () Example: number (false ()) Result: 0lang () Returns true if the language argument matches the language of the xsl: lang element, otherwise it returns falsebool = lang (language) not () Returns true if the condition argument is false, and false if the condition argument is truebool = not (condition) Example: not (false ()) true () Returns Trutrue () EXAMPLE: Number (True ()) Result: 1</p> <p>XPath Examples</p> <p>We will use the cd catalog from our XML Tutorial to Demonstrate Some XPath Examples.The CD Catalog</p> <p>If You Have Studied Our XML Tutorial, You Will Remember this XML Document:</p> <p>(A Fraction of the cd catalog)</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><catalog></p> <p><CD></p> <p><title> Empire Burlesque </ Title></p> <p><Artist> Bob Dylan </ Artist></p> <p><country> USA </ country></p> <p><Company> Columbia </ company></p> <p><price> 10.90 </ price></p> <p><year> 1985 </ year></p> <p></ cd></p> <p><CD></p> <p><title> hide your heart </ title></p> <p><Artist> Bonnie Tyler </ artist></p> <p><country> UK </ country></p> <p><company> CBS Records </ company></p> <p><price> 9.90 </ price></p> <p><year> 1988 </ year></p> <p></ cd></p> <p>.</p> <p>.</p> <p>.</p> <p>.</p> <p></ catalog></p> <p>IF you have ie 5 or higher you can look at the cdcatalog.xml.</p> <p>Selecting Nodes</p> <p>We will demonstrate how to select nodes from the xml document by using the selectnodes function in Internet Explorer. This function takes a location path expression as an argument:</p> <p>Xmlobject.selectNodes (XPath Expression)</p> <p>Selecting CD Nodes</p> <p>The Following Example Selects All The CD Nodes from The CD Catalog:</p> <p>XMLDoc.selectNodes ("/ catalog / cd")</p> <p>IF you have ie 5 or higher you can try it yourself.</p> <p>Selecting The First CD Node</p> <p>The Following Example Selects Only The First CD Node from The CD Catalog:</p> <p>xmldoc.selectnodes ("/ catalog / cd [0]")</p> <p>IF you have ie 5 or higher you can try it yourself.</p> <p>NOTE: IE 5 Has Implement That [0] Should Be The First Node, But According to The W3c Standard It Should Have Been [1].</p> <p>Selecting Price Nodes</p> <p>The Following Example Selects All The Price Nodes from the CD Catalog:</p> <p>Xmldoc.selectNodes ("/ catalog / cd / price") if you have ing it 5 or higher you can try it yourself.</p> <p>Selecting Price Text Nodes</p> <p>The Following Example Selects Only The Text from The Price:</p> <p>Xmldoc.selectnodes ("/ catalog / cd / price / text ()")</p> <p>IF you have ie 5 or higher you can try it yourself.</p> <p>Selecting CD Nodes with Price> 10.80</p> <p>The Following Example Selects All The CD Nodes with a price> 10.80:</p> <p>Xmldoc.selectnodes ("/ catalog / cd [price> 10.80]")</p> <p>IF you have ie 5 or higher you can try it yourself.</p> <p>Selecting Price Nodes with Price> 10.80</p> <p>The Following Example Selects All The Price> 10.80:</p> <p>Xmldoc.selectNodes ("/ catalog / cd [price> 10.80] / price")</p> <p>IF you have ie 5 or higher you can try it yourself.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-67094.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="67094" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.044</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'NN0T8VwlfVlWTw5f0l98ltnqlUtObFXB68ZSoIAtJ4NCed2cI3Y82_2FGO1b_2Bds8UQ1MLDtoZqUN_2BXcD2iQgG1LA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>