I have this code
<div class="kakaa">
<div class="hihi">
<div>dfsfsdf</div>
<div class="haha">
<div id="kaka">ohfoehwf</div>
</div>
</div>
<div class="main">
<div>lorem</div>
</div>
</div>
Now, i want to remove div has class hihi, how to do it become
<div class="kakaa">
<div class="main">
<div>lorem</div>
</div>
</div>
You didn't specify if you're doing this on server-side or client-side. If client-side, no regex is necessary. Use jQuery:
$('.hihi').remove();
Here's a reference: http://api.jquery.com/remove/
If you're doing it server-side, don't use regex (you'll never be able to cover all the possibilities in an HTML tag with regex). Instead use a HTML DOM parser. Here's a very simple one: http://simplehtmldom.sourceforge.net/
Related
I'm looking for a basic grep/regex/awk query to count stock on a website and find instances in a html file that contain this;
</div>
</div>
</div>
</div>
</a>
and not
</div>
</div>
</div>
<div class="product-mark sold-out">sold out</div>
</div>
</a>
I've looked around but my unstanding of regex doesn't really allow me to edit existing examples successfully.
sincerely...... a humble network engineer....
I have an arraylist from which I need to get values where isActive = true, and to display the data in a <div> tag with the use of ng-repeat.
My problem is that I don't want to keep using ng-repeat every time, while fetching values in each <div> tag.
Is there any generic solution which will iterate only once, and I can see the value in <div>, side by side. Please see this attempt:
enter link description here
I want to see a result like this:
You can write your ng-repeat like below.
Whenever it get isActive true, it will create the div section for this.
<body ng-controller="MainCtrl">
<div ng-repeat="tempData in data">
<div ng-if="tempData.isActive == true" >
<div class="col-xs-12" >
<div class="col-xs-4">Plan Type:</div>
<div class="col-xs-8">{{tempData.plantype}}</div>
</div>
<div class="col-xs-12">
<div class="col-xs-4">Term:</div>
<div class="col-xs-8">{{tempData.term}}</div>
</div>
<div class="col-xs-12">
<div class="col-xs-4">Rate:</div>
<div class="col-xs-8">{{tempData.rate}}</div>
</div>
</div>
</div>
</body>
I want to append div using xpath inheriting a parent template.
for ex.
this is parent template
<template id="parent_id">
<div id="header">
<div class="container">
<h1> HEADER </h1>
</div>
</div>
<div id="product">
<div class="container">
<!-- THERE IS SOME CONTENT -->
</div>
</div>
</template>
i want to change like this,
<template id="parent_id">
<div id="product">
<div class="inner">
<div class="container">
<!-- THERE IS SOME CONTENT -->
</div>
</div>
</div>
</template>
i try this,
<template id="product_custom" inherit_id="parent_id">
<xpath expr="//div[#id='product']" position="after">
<div class="inner">
</xpath>
</template>
while replace all content is easy or copy all content to custom template, but it not proper way. i want to wrap a div on content.
I think you cannot do that, because you are going either to override the content or to place your <div/> before, after on inside the selected element.
A simple solution will be to give the id="product" div the class inner by using position="attributes". Or if you really need this, a possible solution is:
replace id="product" with class="inner" with one override using attributes position
define your own template in a second override and call the original one inside it
You will end up with something like this:
<template id="my_parent" inherit_id="foo.parent_id">
<div id="product">
<t t-call="foo.parent_id" />
</div>
</template>
plus the override of the attributes. Never done something like this and the code above is not tested but it could work ;)
If I have HTML like this:
<div id="target">
<div id="a1">
<div class="1">
</div>
<div id="a2">
<div class="2">
<div class="3">
<div class="4">
</div>
<div id="b1">
<div class="1">
</div>
<div id="b2">
<div class="2">
<div class="3">
<div class="4">
</div>
...
...
</div>
...is it possible to select only the first level of div elements from target. So, if I run page.css('#target div').each then I get every single div inside target. If I just want the results to contain the divs with ids ['a1','a2','b1','b2'] is that possible with Nokogiri?
Yes, this is called a child selector
#target > div
Without the > you have a descendant selector, which doesn't care if it's a child, grandchild, great grandchild etc.
I am trying to get all children which has specific class and parent of this parent does not have a specific class.
I am trying a code like this, but it's not working.
$hrefs = $xpath->evaluate("//div[not contains(#class, 'tested-app-section')]/div[#class='product-container-body']/div");
Structure of the HTML I am working with and need to edit a little bit looks like this, other HTML content in <body> is irrelevant. (<body> contains more then just this block of HTML):
<body>
<div class="product-detail-section tested-app-section">
<div class="product-container-head"> ... </div>
<div class="product-container-body"> ... </div>
<div class="product-container-body"> ... </div>
</div>
<div class="product-detail-section publish-app-section">
<div class="product-container-head"> ... </div>
<div class="product-container-body"> ... </div>
<div class="product-container-body"> ... </div>
</div>
<div class="product-detail-section product-specific-section">
<div class="product-container-head"> ... </div>
<div class="product-container-body"> ... </div>
<div class="product-container-body"> ... </div>
</div>
I am trying to avoid in the result the very first <div> box (box with class "tested-app-section"), then I am trying to avoid everything witch class "product-container-head".
But I just cannot find a way how to do it.
Edit: So basically I am trying to get
/html/body/div[contains(#class, 'product-detail-section') AND not contains(#class, 'tested-app-section')]/div[not(#class='product-container-head')]
but this code doesn't return anything...
You are close, but missed a few things. Try this xpath expression and see if it works:
//div[not(contains(#class, 'tested-app-section'))]/div[not(#class='product-container-head')]