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();
Related
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:
How to get the text node of an element?
(11 answers)
Closed 4 years ago.
The text I need is: "BLABLA" from this code:
<td id="1" title="something">
<span>text</span>
<img src="pic.png"></img>
<span><font>something</font></span>
BLABLA
</td>
I can select the <td> element with id, but if I try to get the innerHTML value, I get the whole code inside the <td> element.
You can use the lastChild property to get the last element of a container.
let MyElement = document.getElementById("1").lastChild.data.trim();
console.log(MyElement);
<table>
<tr>
<td id="1" title="something">
<span>text</span>
<img src="pic.png"></img>
<span><font>something</font></span>
BLABLA
</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:
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("&", "&");
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.