1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

document.getElementById for PHP

Discussion in 'PHP' started by Autif, Oct 17, 2019.

  1. #1
    Hello,
    I’m more familiar with JavaScript than I am with PHP. That’s the reason for the framing in the title.

    I’m working on a WordPress site. As far as I can tell, it doesn’t really have any XML which I see several tutorials reference. So, what I would like to know is how to select an HTML element by its id and then echo the result without referencing any XML. Thank you.
    SEMrush
     
    Autif, Oct 17, 2019 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    25,394
    Likes Received:
    3,496
    Best Answers:
    101
    Trophy Points:
    665
    #2
    That's not how php works - it just spits out text that happens to be html.

    You need to find the point in the template that generates the text that needs to change and edit it. You can't just tack code onto the end and expect it to change what's already been generated.
     
    sarahk, Oct 17, 2019 IP
  3. jstech2020

    jstech2020 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Try using "simplehtmldom" library, you can target elements like JS/jQuery
     
    jstech2020, Oct 24, 2019 IP
  4. Andrii Ozemko

    Andrii Ozemko Greenhorn

    Messages:
    48
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    23
    #4
    To be honest, I can not understand why document.getElementById is not suitable for you. It should find your element in the HTML. You don't need XML. Maybe, there is a mistake in your code.
     
    Andrii Ozemko, Oct 24, 2019 IP
  5. sbenjamin81

    sbenjamin81 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    The problem is that PHP is processed before the page is loaded. JavaScript functions can be called via events after the page has been loaded. Use PHP to build the HTML and JavaScript to manipulate it.
     
    sbenjamin81, Oct 24, 2019 IP
  6. NetStar

    NetStar Notable Member

    Messages:
    2,331
    Likes Received:
    486
    Best Answers:
    21
    Trophy Points:
    215
    #6
    You need to read beginner tutorials to understand the languages first.
     
    NetStar, Nov 1, 2019 IP