lundi 10 juillet 2017

jQuery: .append() + replace text with random number in ?

Simplified Introduction: I am trying to append text to a already populated element, without messing with it, in which that appended text is also a random number each page load.

The first issue: I've figured out how to append text with in a element, but I can't seem to figure out how to change the appended text to a random number in a element. I've figured a few ways to do it within elements that are standard or elements, but appending elements to a doesn't work correctly from my understanding.

HTML:

<textarea id="status">test https://twitter.com/test</textarea>

Tested page URL: https://twitter.com/intent/tweet?......

.Append() code used:

function callback() {
    $("#status").append(' aaa');
};
$(document).ready(function () {
    window.setTimeout(callback, 100);
});

The second issue: So I've found a better bit of code that I would have used in a situation that isn't based (in link below), its probably the best solution I seek, however it's function runs on click, I would like this to run every time the page loads; replacing appending text to a random number, not based on a click event method.

What I would like to happen:

<textarea id="status">test https://twitter.com/test 798</textarea>

Footnote: the text excluding the random number between "> … 798<", is assumed to be random with what the user types.

The sandbox Fiddle with code




Aucun commentaire:

Enregistrer un commentaire