Ruby on Rails Sunday, June 21, 2015

Per https://api.jquery.com/category/selectors/

Child Selector ("parent > child")

Selects all direct child elements specified by "child" of elements specified by "parent".

Double check how you are referencing the parent and the children

I grabbed this code from https://api.jquery.com/child-selector/, modified it and it works.  Just remember that multiple elements can have the same css class, but each element must have a

distinct css id.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>child demo</title>
  <style>
  body {
    font-size: 14px;
  }
      </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<ul class="topnav">
  <li>Item 1</li>
  <li>Item 2
    <ul>
    <li>Nested item 1</li>
    <li>Nested item 2</li>
    <li>Nested item 3</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>

<ul id="topnav_id">
  <li>Item 1</li>
  <li>Item 2
    <ul>
    <li>Nested item 1</li>
    <li>Nested item 2</li>
    <li>Nested item 3</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>
<script>
myChildren = $( "ul#topnav_id > li" );
myChildren.css( "border", "3px double blue" );
alert("With id " + myChildren.length);

myChildren = $( "ul.topnav > li" );
myChildren.css( "border", "3px double purple" );
alert("With class " + myChildren.length);

</script>
 
</body>
</html>


Hope this helps.
Liz
On Sunday, June 21, 2015 at 8:06:01 AM UTC-4, Edsil Basadre wrote:
I'm building an app in rails using Nokogiri .. I used puts documents.css("._Ak cite").length and I get the exact length I want but when I tried the id part of the of this puts documents.css("div#mbEnd > cite").length I didn't get the exact, makes 0 length. 

I don't know why nokogiri not recognizing the tag. 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4308acb1-5f9a-4217-86c6-f0178536248a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment