I am using native HTML5 drag and drop to drop some part of HTML into contenteditable element (contenteditable="true")..
problem is next:
some css styles are removed when item is dropped. It looks like some optimization is happened, for example if we have element with color:red and we drop it into droppable area this css property is removed because some of his parents have this same property and value..
for example:
$(function () {
$('.draggablePlaceholder').attr("contenteditable", false);
$('.draggablePlaceholder').off('dragstart').on('dragstart', function (e) {
var dataToSend = $(e.target).attr("data-value");
e.originalEvent.dataTransfer.setData($(e.target).attr("data-value-type"), $(e.target).attr("data-value"))
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td style="color: red;" contenteditable="true">
drop here...
</td>
</tr>
</table>
<span class="draggablePlaceholder" draggable="true" contenteditable="false"
data-value="<table>
<tbody><tr>
<td style=" color:red; font-size:19px; ">SOME TEXT</td>
</tr>
</tbody></table>" data-value-type="text/html">
ITEM FOR DRAG
</span>
when you try to move "SOME TEXT" into droppable area the result is:
1 css property: font-size:19px;
instead of 2 css properties: color:red; font-size:19px;
so color:red is removed
is there way to skip this "optimization", so original code is copied?
Related
<table>
<tbody>
<tr class="positive">
<td class="happy">12</td>
<td class="happy">7</td>
<td class="happy">69</td>
</tr>
</tbody>
</table>
▲ this is the origin html code.
td.happy(#>10) {color:red;}
td.happy(#>50) {color:blue;}
▲ this is the css code what i want. (Imagine)
i'd like to apply CSS style when the number greater than specific number(10, 50)
i'v tried Java-script, and it worked, but i want to make the website only with html and CSS as possible.
Is there any way to select the text's number, which is in the tag?
You can't with pure css,you must help of jquery:
$(document).ready(function(){
$('tr.positive td.happy').each(function(){
number = parseFloat($(this).text());
if(number > 10)
$(this).addClass('greater10');
if(number > 50)
$(this).addClass('greater50');
})
})
td {
border: 1px solid #000;
}
.greater10 {
color: red;
}
.greater50 {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table>
<tbody>
<tr class="positive">
<td class="happy">12</td>
<td class="happy">7</td>
<td class="happy">69</td>
</tr>
</tbody>
</table>
If you read the specification, no.
You can match on an element, the name of an attribute in the element, and the value of a named attribute in an element. The only control you can do is if a tag is empty.
Not from css, if you are trying to avoid a whole new js page then maybe consider embedding the js in your HTML.
The structure is like this(taken from browser), it is dynamically generated in share point Mysite. I do not have control over HTML. I need to hide the whole tr using css. The catch is that there are numerous similar tr structure in the page but with different text in span.Please suggest a way to hide only the tr with text Social Notification Properties
<tr class = "ms-WPHeader">
<td colspan ="3">
<div class = "ms-WPTitle">
<span>
Text -Social Notification Properties
I have tried this so far but failed.
td[class ~="ms-WPHeader"]+tr+td+div+span[Text ~="Newsfeed"]
{
display:none;
}
and this
.ms-WPHeader ~ .ms-WPTitle.span[Text ~="Newsfeed"]
{
display:none;
}
using this hides all the span which is obvious
.ms-WPTitle span
{
display:none;
}
You can use :contains to neglect the inability of CSS to select text node.
Below there are two tables in which the second table text is visible.
$(".ms-WPHeader:contains('Text-Social Notification Properties')").css("display", "none");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr class="ms-WPHeader">
<td colspan="3">
<div class="ms-WPTitle">
<span>Text-Social Notification Properties</span>
</div>
</td>
</tr>
</table>
<table>
<tr class="ms-WPHeader">
<td colspan="3">
<div class="ms-WPTitle">
<span>I am visible though</span>
</div>
</td>
</tr>
</table>
You can't select elements with a specific text inside via CSS. What you can do though is to via jQuery look for that element and then add a class to it, so that you then can select it via CSS.
$("span:contains('Social Notification Properties')").addClass('hide');
And then in CSS
.hide{
display:none;
}
this is what i still suggest that you can use like this
$('table').addClass("hide_this_tr");
.hide_this_tr tr{
display : none;
}
<table>
<tr class="WPHeader">
<td colspan="3">
<div class="WPTitle">
<span>Text-Social Notification Properties</span>
</div>
</td>
</tr>
</table>
<table>
<tr class="WPHeader">
<td colspan="3">
<div class="WPTitle">
<span>I am visible though</span>
</div>
</td>
</tr>
</table>
As what i understand about what you want to achieve this is what my try is.
There's a specification for :contains('') pseudo-class, but I'm not able to make it work on any browser.
http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors
But jQuery make this selector work as Gustaf said :
$("span:contains('Social Notification Properties')");
It's the only way to achieve this at the moment.
Without using jQuery, plain JavaScript using XPath (as mentioned in comments):
var snapshot = document.evaluate(
"//tr[contains(concat(' ', normalize-space(#class), ' '), ' ms-WPHeader ')][contains(.//span, 'saurus')]",
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
);
for (var i = 0; i < snapshot.snapshotLength; i++) {
snapshot.snapshotItem(i).classList.add("highlight");
}
.highlight {
color: red;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<table>
<tr class = "ms-WPHeader">
<td colspan ="3">
<div class = "ms-WPTitle">
<span>
Irrelevant text
</span>
</div>
</td>
</tr>
<tr class = "ms-WPHeader">
<td colspan ="3">
<div class = "ms-WPTitle">
<span>
A wild stegosaurus appears!
</span>
</div>
</td>
</tr>
<tr class = "ms-WPHeader">
<td colspan ="3">
<div class = "ms-WPTitle">
<span>
More irrelevant text
</span>
</div>
</td>
</tr>
<tr class = "wrongClass">
<td colspan ="3">
<div class = "wrongClassTitle">
<span>
Brontosaurus in a wrong TR
</span>
</div>
</td>
</tr>
</table>
</body>
</html>
The XPath for "having a class", simple in CSS, is a bit of a pain in XPath; but it can be simplified quite a bit if you know the exact class attribute (i.e. "there will be no other classes but ms-WPHeader there"):
"//tr[#class='ms-WPHeader'][contains(.//span, 'saurus')]"
You can use :nth-child() if the structure of your page doesn't change :
To hide the 1st tr with the class ms-WPHeader (Be carreful: this will hide every 1st tr in each table):
table tr.ms-WPHeader:nth-child(1) {//hide the 1st tr in table
display: none;
}
JSFidlle: http://jsfiddle.net/ghorg12110/no891emk/
span is a webelement so you can select this using CSS Selector.
and then you can do WebElement.getText() to retrieve the text. No need to use xpath for this.
<tr>
<td colspan="2" style="tex-align:center">
<button onclick="myFunction()">Enquire</button>
<script>
function myFunction() {
alert("Thank you, your enquiry has been submitted!");
}
</script>
</td>
</tr>
My enquire button will not move from the left of the page. I had a previous button that had no function and used a different code to make a popup box happen. It works, but the previous style and colspan codes have no effect on the new code.
The word text has two ts in it.
style="text-align:center"
There is just a spelling mistake in your code:
you gave
tex-align:center;
Its..
text-align:center;
Do:
style="text-align:center"
and add some CSS to the HTML table:
table{
width: 100%;
}
Working Demo
Here is my code. I made this - when I hover table cell then its background image changes, that was easy.
But I would like to make that when I hover cell 5 with class="down" in first table then second table display attribute changes from none to block
I searched for this and I ended up with all this code, and it isn't working.
I need to use pure CSS without JavaScript.
Where is the problem and what did I do wrong?
HTML
<table border="0" class="table">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td class="down">5</td>
</tr>
</table>
<table border="0" class="table2">
<tr>
<td>row2</td>
</tr>
<tr>
<td>row3</td>
</tr>
</table>
CSS
.table
{
left:200px;
position:absolute;
}
td
{
background-image:url(poga1.png);
height:70px;
width:100px;
}
td:hover
{
-webkit-transition:1s;
background-image:url(poga2.png);
}
.table2
{
display:none;
left:616px;
position:absolute;
top:77px;
}
.down:hover .table2
{
display:block;
}
You can't really do this with CSS unless Table2 is a child of Table1. It can be done very easily with JavaScript though (w/ jQuery in this instance). Check out my example here:
http://jsfiddle.net/Pb8dw/1/
$(document).ready(function() {
$(".down").mouseover(function(){
$(".table2").show();
});
$(".down").mouseout(function(){
$(".table2").hide();
});
});
This is the block of code that does the hide/show on hover. I took the liberty of updating your source code so it's easier to see.
Update: If you absolutely, positively, had to do it without JavaScript, here's how it would be down with just CSS and HTML:
http://jsfiddle.net/Pb8dw/2/
The line .down:hover .table2 is looking for an element with class table2 inside an element with class down. You can only do what you want in pure CSS if your tables are nested. Here's how you might do what you want using jQuery:
$(document).ready(function() {
$('.down').hover(function() {
$('.table2').show();
}, function() {
$('.table2').hide();
});
});
Here's a demo: http://jsfiddle.net/mchail/b6PKT/
I added a border on the td elements so it's easier to see when your hover event should trigger.
Hi I would like to change the height of a HTML table from 690 to 400 in the 2 seconds in a smooth transition by clicking a button. Is there a way to do this in pure CSS? Here is my example:
<html>
<head>
<title>Test</title>
</head>
<body>
<table>
<tr>
<td>
<button type="button">Click Me!</button>
</td>
</tr>
<tr>
<td height="690" width="1280> <--- This cell needs it height to change to 400px when the button is clicked.
Cell 1
</td>
</tr>
</table>
</body>
</html>
You cannot do that purely with CSS, however you can easily do it with jQuery:
// Use a more specific selector by ID or class
$('button').click(function (event) {
$(this).closest('tr').next().children('td:first').animate({height: 400}, 2000);
});
You will need to use Javascript.
Use function click() {
document.getElementById('id').setProperty('style', 'height:100px;');
}
And for the button use this - <button onclick="click();">BUTTON</button>
give id to button (clickbut) and for the table(tableheight)
then use jquery
$(document).ready(function(){
$("#clickbut").click(function(){
$("#tableheight").css('height','somevalue eg:300px');
});
});