prototype: loop with each and select childs by classname - prototypejs

I have following structure:
html structure:
<table class="structure">
<tr>
<td class="id">
<div class="product-id">123</div>
</td>
<td class="article">
<ul name="attribute[151]">
<li class="active"> A</li>
<li>B</li>
</ul>
</td>
</tr>
<tr>
<td class="id">
<div class="product-id">456</div>
</td>
<td class="article">
<ul name="attribute[151]">
<li class="active"> A</li>
<li>B</li>
</ul>
</td>
</tr>
</table>
I want to loop every tr element to get the li element with class active. I pick tr because i also want to select the product-id.
how can i select a css selector inside my each loop?
prototype:
$$('.structure tr').each(
function (index) {
//wrong
console.log(index.down(".article li.active a'").readAttribute('rel'));
}
);
}

So you can simplify your javascript like this
$$('.structure tr').each(
function (index) {
console.log(index.down('li.active a').readAttribute('rel'));
//wrong
console.log(index.down(".article li.active a'").readAttribute('rel'));
// extra single quote ^^^^
}
);
}
You also have an extra single quote (') in the down() method which might be confusing the CSS selector engine (which is Sizzle)

Related

Bootstrap Striped-table not working with Vuejs

I am creating a friends component that lists users friends based on a response from an endpoint.
I want to render the responses into rows of a table as part of this I would like to use the bootstrap striped-table class
https://getbootstrap.com/docs/4.0/content/tables/#striped-rows
when I do a v-for the table renders correctly but the rows are only showing one background color
This is my template code
<template>
<div>
<h5 class="mb-4">Friends</h5>
<table class="table table-borderless table-striped ">
<tbody>
<div v-for="(friend, index) in UserStore.friends">
<tr>
<td class="text-center" style="width: 100px;">
<img style="width: 100px;" :src="friend.avatar" alt="User Image" class="rounded-circle">
</td>
<td>
{{friend.name}}<br>
<small>29 years old on Friday</small>
</td>
<td class="text-center" style="width: 80px;">
<i class="fa fa-gift"></i>
</td>
</tr>
</div>
</tbody>
</table>
<div v-if="!UserStore.friends">
<h6>You don't have any friends :(</h6>
Lets solve that Right now!
</div>
</div>
</template>
You should use a template element to render these rows. .table-striped works with sibling rows and in your code the rows are not siblings because they each have a div parent, so each row is seen as the first row.
<tbody>
<template v-for="(friend, index) in UserStore.friends">
<tr>
<td class="text-center" style="width: 100px;">
<img style="width: 100px;" :src="friend.avatar" alt="User Image" class="rounded-circle">
</td>
<td>
{{friend.name}}<br>
<small>29 years old on Friday</small>
</td>
<td class="text-center" style="width: 80px;">
<i class="fa fa-gift"></i>
</td>
</tr>
</template>
</tbody>

Selecting the Parent of the Parent element. Tables/Watir/Ruby

Hey i am trying to select the parent of the parent element i suppose. I have a table in which i am trying to use Watir/Ruby to select the edit or delete button from the same row but in a different coloumn, example.
Name 1 -> Edit Icon -> Delete Icon
Name 2 -> Edit Icon -> Delete Icon
Example code below:
<html>
<body>
<table class="table-responsive">
<thead>...</thead>
<tbody>
<tr>
<td class="col-name">Name 1</td>
<td>
<a class="edit" href="/">
<span class="icon-edit"></span>
</a>
<a class="delete" href="/">
<span class="icon-delete"></span>
</a>
</td>
</tr>
<tr>
<td class="col-name">Name 2</td>
<td>
<a class="edit" href="/">
<span class="icon-edit"></span>
</a>
<a class="delete" href="/">
<span class="icon-delete"></span>
</a>
</td>
</tr>
<tr>
...
</tr>
<tbody>
</table>
</body>
</html>
So far i have tried this but it is not working. I get an error TypeError: can't convert Hash into an exact number
table = #browser.table.when_present(:class => "table-responsive")
iconrow = table.span(:text => "Name 1").parent
if iconrow.a(:class => "edit").exists?
iconrow.a(:class => "edit").click
end
There might be a couple issues with the code:
* The :class locator is being applied to when_present rather than the table itself.
* The element with "Name 1" is a td rather than a span.
Try:
table = #browser.table(:class => "table-responsive").when_present
iconrow = table.td(:text => "Name 1").parent
if iconrow.a(:class => "edit").exists?
iconrow.a(:class => "edit").click
end

How to add Pagination in laravel 5

I need to show one row per page.
this my contoller class code
public function showcontent($id)
{
$story=storybook::find($id);
$content=storycontent::where('titleid', $story['id'])->paginate(1);
//return $content;
return view('storyBook/viewStory',compact('story','content'));
}
this my view class code
#foreach($content as $content)
<?php $a=null; ?>
<?php $b=null; ?>
<?php $a=$content->file1; ?>
<?php $b=$content->file2; ?>
<table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px">
<tr>
<td style="width: 340px"><img src="/{{$a}}" alt="Mountain View" style="width:330px;height:300px;"></td>
<td style="width: 340px"><img src="/{{$b}}" alt="Mountain View" style="width:330px;height:300px;"></td>
</tr>
</table>
<br>
#endforeach
In here i get only 1st row, rest of the rows not visible..
I do not know how to add pagination.
#foreach($content as $content)
So first of all change the naming of vars for example:
#foreach($content as $entry)
<table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px">
<tr>
<td style="width: 340px"><img src="/{{$entry->file1}}" alt="Mountain View" style="width:330px;height:300px;"></td>
<td style="width: 340px"><img src="/{{$entry->file2}}" alt="Mountain View" style="width:330px;height:300px;"></td>
</tr>
</table>
<br>
#endforeach
$content->links()
As you can see I've added $content->links() after foreach loop. This is the method of Paginator that print out the pagination navigation.

Xpath match current node or one of child nodes

I'm having a trouble creating Xpath for following HTML:
<html>
<body>
<table class="tablesorter">
<tbody>
<tr class="tr_class">
<td>{some td info}</td>
<td>{some td info}</td>
<td>
<span class="span1">
<span class="span2">Out</span>
<span class="span3">SMTH</span>
<span class="span4">Out</span>
</span>
</td>
</tr>
<tr class="tr_class">
<td>{some td info}</td>
<td>{some td info}</td>
<td>In</td>
</tr>
<tr class="tr_class">
<td>{some td info}</td>
<td>{some td info}</td>
<td>In</td>
</tr>
</tbody>
</table>
</body>
</html>
What I want is to create Xpath that will return me content of each third td node (if it doesn't have children) or a content of it's span that has class="span2".
For example, for this html it should return
Out,In,In
I have Xpath that will return needed span node, it looks like:
//table[#class = 'tablesorter']//td[3]/descendant::*[#class='span2']/text()
and I have Xpath that will return me simple content of each 3d td nodes:
//table[#class = 'tablesorter']//td[3][count(descendant::*)=0]/text()
But I need only one Xpath, because for me it is necessary to have a right ordering of 'In' or 'Out' values (their ordering in the table)
This will do it, no idea how robust it will be for your "corpus":
//table[#class="tablesorter"]/tbody/tr/td[3]/descendant::text()[normalize-space(.)!=""]
['Out', 'In', 'In']
Update
//table[#class="tablesorter"]/tbody/tr/td[3]/descendant::text()[normalize-space(.)!=""][parent::td or parent::span[#class="span2"]]

onmouseover action not working...what should i do?

<span id="hintText_123" style="display:none">
<table id="hintTable" style="width:100%;border:0px none;padding:0px;border-collapse:collapse;margin:0px;background-color:#7F9DB9;">
<tr style=background-color:#56718A;>
<td style="color:white;font-size:11px;font-weight:bold;padding:2px">
Title
</td>
<td style="width:5%;padding:2px">
<img alt="" src="close.gif" style="width:15px;height:15px" align=middle onclick=parent.hidetip()>
</td></tr>
<tr style="background-color:#8CA7C0;"><td style="color:white;font-size:10px;padding:2px" colspan=2 >Description
</td>
</tr>
</table>
</span>
This is the table i want to display on mouseclick event of the below item
<span style="display:block;" onmouseout="toggleHelp('helpGrp_123',false,'group_field_name_123')" onclick="showhint(document.getElementById('hintTextGrp_123') , this, event, '380px')">
Hello!!!
</span>
</tr>
but the table is not getting displayed on clicking Hello!!!
<script>
function callMe()
{
var tmp = document.getElementById("hintText_123");
alert(tmp.style.display);
tmp.style.display = 'block';
}
</script>
Call on onmousemove="callMe()"

Resources