How to get innertext of a DIV using javascript? [duplicate] - javascript

This question already has answers here:
how to use simple html dom get a div inner text
(4 answers)
Closed 9 years ago.
How to get inner text of a DIV controller using java script?

The short answer:
document.getElementById("id-of-div").innerText
The long answer, given that you've tagged the question with asp.net-mvc-3, is that this will be run in the browser, not on the server (where ASP.NET runs). There is no immediate way to get content from the browser to the server without sending a request. I'm guessing that you may want to make an ajax call to a new controller action from the page, but this depends on when the text changes, and what you want to do with it.

Suppose you have a div declared as:
<div id="someDiv">
some content goes here
</div>
You can get its value by:
// javascript
document.getElementById("someDiv").innerHTML
// jquery
$("#someDiv").html()

Related

Determine when DOM Loaded [duplicate]

This question already has answers here:
execute function after complete page load [duplicate]
(16 answers)
Closed 3 years ago.
I am in need of some JS assistance.
I need to run some code after the DOM was updated.
For example: when I click a button, it fires a function. I need to run that function code and when the DOM is fully updated, run some more code. How could I go about doing this in a clean fashion?
I am sure this is relatively simple but I am drawing blanks. I am using jQuery.
$('.btn').click(function() {
do some stuff
// then ensure dom has fully updated and do some more????
})
DOM updates are synchronous. Just put the code where your comment is.

How to pass text from textarea to reflect or show in another page, without losing the formatting? [duplicate]

This question already has an answer here:
Still get <br> in textarea
(1 answer)
Closed 5 years ago.
I am making an application using javascript (no JQuery) and php. I have a textarea form -which applies - space formatting. But when I send the values from this textarea to another page using PHP post command ..the spacing is gone. How can I reflect the content of the textarea along with spacing?
It is very easy..
use 'n2blr` function.
The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.
See demo for understand it well

how to write css for inner html of iframe [duplicate]

This question already has answers here:
How to apply CSS to iframe?
(28 answers)
Closed 8 years ago.
have one question, i trapped in a prob..The problem is like that --->I have to manipulate the css of inner html of iframe but the content of this iframe is not coming from same domain so how can it makes possible
live eg.-u can take ("tweets feed in our website ,it comes from another domain tweeter.com/bla....blaa but render on our web page encapsulate with iframe,so how can i style tweet section in our website")
i have tried by jQuery but its not working can u plz help me out in that ?
Thanks in advance Smile | :)
The comment by Sico refers to an existing question on stack that answers this as not possible. How to change style of iframe content cross-domain?
If you are looking to do this in Javascript or JQuery that answer is correct, basically. You Cannot. It is not possible to alter the content of another domain.
A solution however, would be to use PHP to fetch the content of the target page and make it your own, there are several ways to do this such as curl http://php.net/manual/en/book.curl.php. You can then redisplay that content in any manner you like and apply any style you like. You can even ditch the iframe and inline it right into the rest of your content.
Be warned however, depending on the source domain, they may not approve of their content being re-used in this manner.

Changing the Title of a Web Page Using Javascript [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to dynamically change a web page's title?
I am trying to set the title of my web page using JavaScript because I want something that is stored in localStorage to be part of the title. The approach that I am trying is to use document.createElement('title'), but I cannot set the text of the title when I do that. Is there a way to set the text of the title this way or is there a different way that I should be doing this?
Use
document.title = 'Your desired title';
Your site should have a <title> element
If it does, you simply add this to your scripts and call it
function changeTitle(title) { document.title = title; }
The question is why are you doing it?
You can just do something like, document.title = "This is the new page title.";, but this would not work for seo etc, as most crawlers do not support JavaScript.
If you want this to be compatible with most of the important crawlers, you're going to need to actually change the title tag itself, on the server side which would involve (PHP, or the like).

Change span text? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I change the text of a span element in javascript
Well, I've searched a lot for the answer to this, but still I couldn't find it. What I did find didn't work.
What I'm trying to do is, basically, using JavaScript: At the browser's bar, not via Greasemonkey or something else, edit a span's text .
This' the span that contains the text I want to edit:
<span id="serverTime">5:46:40</span>
The time within is just random, don't pay attention to it, it's what I want to edit using javascript..
I'm a newbie so yeah :\
document.getElementById("serverTime").innerHTML = ...;
Replace whatever is in the address bar with this:
javascript:document.getElementById('serverTime').innerHTML='[text here]';
Example.

Categories

Resources