Change span text? [duplicate] - javascript

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.

Related

How to change certain part of alert message color and font in Java script [duplicate]

This question already has answers here:
How to change the style of alert box?
(13 answers)
Closed 9 months ago.
I have been trying to change certain part of text to bold and red color.
It's not working on Microsoft Edge.
My code:
alert("Hi how are you my friend");
Need to make text : "friend" as bold and red color
I tried this but does not work
alert("Hi how are you my <b> <background-color = red"> friend </b>);
Any solution is much appreciated
It is impossible i searched for this problem a lot, but you can make your window ,it isn't hard to find tutorials.
e.g https://www.delftstack.com/howto/javascript/javascript-customize-alert-box/
Unless you use the dialog tag in jQuery to create the alert,it somehow has been styled in the jQuery theme already.... Styling JavaScript alert box on my end here I don't think it's possible

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

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()

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).

Update 2 exact same images source using javascript [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Update 2 exact same images source using javascript
I using PHP captcha called Cryptographer captchan.fr site
I need to use 2 captcha on same page but I have problem they do get generated but when I click refresh only first one refreshes, refresh code looks like this.
document.images.captcha.src='cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
I tried this code but it only works for first one anyway
document.getElementById('captcha').src='cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
Now I wanted to do something like this i added name="captcha" to image but this does not work for some reason can someone help me fix it?
document.getElementsByName('captcha').src='cryptographp.html?cfg=0&&+Math.round(Math.random(0)*1000)+1;
I also have jquery attached to page if thats easier.
I tried to remove id and use class but still this does nothing
$('.captcha').src='cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
because saying undefined reference.
You're almost there! You need to use .attr in jQuery, as there is no .src method
$('.captcha').attr('src', 'cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1);
Ensure your two <img> has the class captcha
the correct syntax is
$(".captcha").attr('src',"image url")

jquery: how to use an id selector? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
what does #someDiv mean?
i am doing this:
onmouseover="evt.target.setAttribute('opacity', '0.5'); $('#someDiv').show();" onmouseout="evt.target.setAttribute('opacity','1)'); $('#someDiv').hide();"
but i guess i need something called an ID selector?
anyway how do i make it so that when there is a mouseover the object, i get a little popup ?
$('#someDiv') is selecting the element with ID="someDiv", so selectors might not be your problem.
Apart from using the onmouseover event attribute, the code you provided should basically work. Are you seeing any JS errors, or have other debug results you could share?
Edit:
It's probably (maybe?) unrelated to your problem, but you should consider moving all the JS logic to a linked JS file instead of using the onmouseover property. jQuery's $('#your-selector').mouseover() method is a much better way to handle this. (http://api.jquery.com/mouseover/)

Categories

Resources