Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Learning basic

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #43792
    JustChill
    Participant

    Hello,
    today I’am learning javascript(jquery). And I want to ask why in html don’t printing the sText variable?

    http://codepen.io/anon/pen/GdKcf

    P.S. Sorry for dumb questions :D.

    #130232
    hotpink
    Member

    The main problem is that the variable: sText is defined outside the “scope” of where you are calling it.

    When you define a variable inside of a function, it is available only within that function.

    Here is a fork of your codepen that demonstrates the concept
    http://codepen.io/jessecfisher/pen/DFzmB

    If you don’t understand the code changes I’ve made, ask more questions :)

    ## Codepen tips

    Here is a simplified version of your code that takes advantage of Codepen features.

    You can see that the

    jQuery can be included by clicking the gear image on the top right of the JS box.

    http://codepen.io/jessecfisher/pen/lJtfH

    #130233
    theacefes
    Member

    EDIT @hotpink beat me to it. :) Was trying to keep it as close to the original as possible. Also, what may work in Codepen may not work for OP’s personal projects.

    [Try this](http://codepen.io/katbella5/pen/eqiLfhttp://codepen.io/katbella5/pen/eqiLf”)

    #130234
    JustChill
    Participant

    Thanks for clearly answer. :) But I have one more question.
    It’s imposible from the JS code print in to the html code? I mean in the html code shows how it looks all code with (JS + HTML, these things **slidebox.wrap(“

    I wrote more there thins in JS. http://codepen.io/anon/pen/GdKcf

    #130308
    JustChill
    Participant

    Possible to do it?

    #130310
    CrocoDillon
    Participant

    Not sure if I understand the question but you can add elements with JS, for example:

    $(‘body’).append(‘

    ‘);

    or

    $(‘body’).append($(‘

    ‘).addClass(‘container’));

    See http://api.jquery.com/category/manipulation/ for more jQuery DOM manipulation functions.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.