• If I were to obtain the position of the last character of a paragraph, would the .indexof() method be the best to use ?
    Any suggestions?

Viewing 9 replies - 1 through 9 (of 9 total)
  • So you want the string position of the last character in a paragraph??

    You could use some javascript I would think to break up the paragraphs.

    V

    depends what you are trying to do, you might want to look at

    var n = str.length;

    to get the length of the string then something like

    var x = str.charAt(n);

    indexof() is used when you know what you are looking for but not sure where it is in the string

    Thread Starter NollieHeel

    (@nollieheel)

    cool thanks! Ill try it out. it’s only one paragraph that Im dealing with

    Thread Starter NollieHeel

    (@nollieheel)

    okay , so Ive named my <p> tag “abouttext”.

    $(“a.about”).click(
    function () {
    var x = $(“#abouttext”).length;
    var pos = $(“#abouttext”).charAt(x);
    alert(pos);
    }
    );

    whats wrong with my try here? Im just using the alert for testing purposes.

    Thread Starter NollieHeel

    (@nollieheel)

    ok so I tried this, for sake of learning:

    $(“a.about”).click(
    function () {
    var blaze = $(“#abouttext”);
    var x = blaze.length;
    alert(x);
    }
    );

    the result in the window is 1. Which is weird, because the <p> has at least a couple hundred characters. the text in the <p> tag is all 0’s and 1’s. Does that have anything to do with it?

    Thread Starter NollieHeel

    (@nollieheel)

    $(“a.about”).click(
    function () {
    var blaze = $(“#abouttext”);
    var x = blaze.text().length;
    alert(x);
    }
    );

    The result of this was 833. cool.

    Thread Starter NollieHeel

    (@nollieheel)

    Can anyone tell me why this wont work ?

    $(“a.about”).click(
    function () {
    var blaze = $(“#abouttext”);
    var x = blaze.text().length;
    var pos = blaze.charAt(x);
    alert(pos);
    }
    );

    Thread Starter NollieHeel

    (@nollieheel)

    ok here’s the problem in its real context.
    Trying to animate some text.
    Basically the idea is to remove the last character, fill in it’s position with it’s neighboring character (to its left, of course), and then remove it again. Repeat this until the rest of the text is gone.

    Below is my attempt.. that doesn’t work. Note that I declared my variables and functions before the click event, which starts the animation. My guess is I probably don’t have proper syntax either.

    var x = $(“#abouttext”);
    var pos = x.charAt(833);

    function Continue () {
    var y = pos.prev();
    pos.append(y);
    pos.fadeOut(“fast”, linear, function Continue());
    };

    $(“a.about”).click(
    function () {
    pos.fadeOut(“fast”, linear, Continue());
    }
    );

    help!

    Thread Starter NollieHeel

    (@nollieheel)

    still trying, but here’s my last attempt for the day. Think I’m getting a bit closer:

    var x = $(“#abouttext”);
    var odg = x.text().charAt(832);

    function animContinue () {
    var y = x.text().charAt(832);
    y.fadeOut(“slow”, animContinue());
    }

    $(“a.about”).click(
    function () {
    odg.fadeOut(“slow”, animContinue() );
    }
    );

    I’m basically trying to remove the characters one-by-one, but in a fixed location on the screen.. Almost as if the last character were a vacuum for all the preceding characters.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Method’ is closed to new replies.