This question already has answers here:
JavaScript/jQuery: replace part of string?
(2 answers)
Closed 6 years ago.
<tr>
<td nowrap="true" valign="top" width="113px" class="ms-formlabel"><h3 class="ms-standardheader"><a name="SPBookmark_Category"></a>Category</h3></td>
<td valign="top" class="ms-formbody" width="350px" id="SPFieldChoice">
<td width="350" class="ms-formbody" id="SPFieldChoice" valign="top">
<!-- FieldName="Category"
FieldInternalName="Category"
FieldType="SPFieldChoice"
-->
Health & Fitness
</td>
</td>
</td>
</tr>
I need to replace & with & using jQuery from Health & Fitness. How can I do that.
Using javascript string .replace function.
var el = $('#SPFieldChoice');
el.html(el.html().replace("&", "&"));
Working Fiddle
Find td text and use replace .
$('td#SPFieldChoice').text().replace('&','&')
1) You should not have the same IP for different
2) use $('idOfYourNode').text().replace("&", "&");
Related
This question already has answers here:
What do querySelectorAll and getElementsBy* methods return?
(12 answers)
getElementsByName() not working? [duplicate]
(2 answers)
Closed 2 years ago.
I'm trying to click a button on a webpage.
<table class="table div-table list-pc bg-white" style='font-family: "gulim", sans-serif;'>
<tr>
<td colspan=2 align=left><input type="checkbox" name="check_all" id="check_all">SelectAll</td>
<td colspan=2 align=right><input type="button" name="btn_delete" value="DeleteAll" onclick="javascript:GoCheck()"></td>
</tr>
I tried to do it as below but it didn't work.
document.getElementsByName("btn_delete").click();
Help me, please.
getElementsByName returns element collection, you need to take first element of this collection. Than it'll work.
document.getElementsByName("btn_delete")[0].click();
This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 8 months ago.
Learning Javascript at the moment, so please bear with me. I created a table in my connected.html and I am trying to obtain the element between the <td> tags in my event-page.js. I used document.getElementByID("tokens"), however I get null, I want to get 12. I think I have to do more with document.getElementByID("tokens") I used .innerText and .innerHTML but those didn't work. Any help would be appreciated! Sorry for such a simple problem.
*Note: The function in event-page.js is called when a button is clicked by the user.
connected.html
<html>
<head>
</head>
<body>
<table>
<tr>
<td colspan="4" class="info">Tokens</td>
</tr>
<tr>
<td id="tokens">12</td>
</tr>
</table>
</body>
</html>
event-page.js
chrome.extension.onMessage.addListener(function(request, sender, sendResponse){
if (request.action.split(':')[0] === 'got-it'){
yt_name = (request.action.split(':')[1])
console.log(yt_name)
let table = document.getElementById("tokens")
console.log(table)
}
})
This Works, that means your EventListener are called before the DOM is loaded.
let table = document.getElementById("tokens")
console.log(table)
<table>
<tr>
<td colspan="4" class="info">Tokens</td>
</tr>
<tr>
<td id="tokens">12</td>
</tr>
</table>
This question already has answers here:
React colspan not working
(6 answers)
Closed 5 years ago.
I'm trying to use a <table>...</table> inside React. I have this:
<table>
<tbody>
<tr>
<td> ... </td>
<td> ... </td>
</tr>
<tr>
<td colSpan={2}> ... </td>
</tr>
</tbody>
</table>
React ignores colSpan. I've been dealing with this for a while. I found some question like this here in Stackoverflow, and the answers are to camelcase the colspan, but it doesn't work for me. It goes the same in <th colSpan={2}>...</th> What am I missing here?
It's
<td colSpan='2'>
Not
<td colSpan={2}>
This question already has answers here:
jQuery : remove element except inside element
(4 answers)
Closed 8 years ago.
I need to remove a single tag from the DOM using jQuery or JavaScript. I only need to remove the enclosing tag, not the content inside the tag.
remove(), detach(), empty() methods cannot be applied as they remove the whole content as well.
for example:
<table border="1" style="width:300px">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
need to remove only the <table></table>.
Currently DOM looks like this
<table style="width:600px">
<tbody><p> Number - Name - <br></p>
<p> 111 - ABC - <br></p>
<p> 222 - KLM - <br></p>
<p> 333 - NOP - <br></p>
<p> 444 - HIJ - <br></p>
</tbody></table>
Thank you in advance.
Try to .unwrap() it, but the result would be an invalid html,
$('tr').unwrap();
var text=$("table").text();
$("table").parent().html(text);// now at the place of text come
$("table").replaceWith($("table").html());
With Jquery :
$('table').each(function(){
$(this).replaceWith($(this).html());
});
This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 8 years ago.
I don't know what I'm doing wrong. This is a 2 part question. Please see code below. First, it keeps saying that the variable capitals is null. Second, I'm unable to get innerHTML working. I'm not sure why it isn't working. I know I have document.write which I'm not suppose to use so I'm working on understanding getElementbyId.innerHTML to work.
HTML
<form name="shares">
<table>
<tr><td>Enter information here:</td></tr>
<tr>
<td>Capital to Invest</td>
<td id="capitalr"><input type="text" name="capital"> </td>
</td>
</tr>
<tr>
<td>Price per share</td>
<td><input type="text" name="price" onchang="calculate();"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="Compute" onclick="calculate()"></td>
<tr><td>The quantity you can be:</td></tr>
<tr>
<td>No. of shares</td>
</tr>
<tr>
<td>Change</td>
</tr>
</table>
<p id="hello"></p>
</form>
JavaScript
var capitals = document.getElementById("capitalr");
var x = capitals.id;
var pps = document.shares.price.value;
function calculate () {
document.write("Capital = " + capitals +"<br>");
document.write("Price per share is = " + pps);
}
document.getElementById("hello").innerHTML="Hello";
1) The <tr> for your button doesn't have a </tr>.
2) There's a timing problem -- you need to put your code in a function that executes at onload time.
<body onload="fnonload();">
I suggest you use "console.log" statements as a debugging tool to see how your code is progressing. That's helped me a lot.