开发者

Get ID of a DIV element using php

开发者 https://www.devze.com 2023-02-09 10:04 出处:网络
-- edit -- I\'ve made the question far more detailed here: Drupal aggregators and tailored output -- original question --

-- edit --

I've made the question far more detailed here: Drupal aggregators and tailored output

-- original question --

Is it possible to get the id of an html div element on any given page using php so I can do something like:

if($divid == 'id-of-div') { do this; }

--edit--

To clarify:

I have a page on a website. It could be any page. On that website I have a div element which I want to be able to target using php to populate depending on the id of that div element. For example:

if($divid == 'div1') { $output = 'div 1 output'; }
if($divid == 'div2') { $output = 'div 2 output'; }
return $output;

Hope that helps...

-- re-edit(!) --

I've commented below but think it would probably be more useful in here:

Hi, sorry I'm not being more clear. I'm not a php expert (as you can probably tell!). I am theming a Drupal site at the moment and have a function that generates output to a block. These are the same kinds of block but they are unique by virtue of their div id's. I want to be able to tailor the generated ou开发者_开发技巧tput to these depending on which div area it is. Does that make any more sense? Thanks for your help so far, by the way


I think you are misunderstanding the way PHP works. PHP is usually used to generate the raw HTML code of a page, but you usually don't use it to traverse the DOM of the output like you can in jQuery. (In theory, you can do this using output buffering and a HTML parser class, but it makes no sense at all.)

There shouldn't be the need to find elements by ID because in order to put something into a DIV, you can do the following:

<div id="mydiv">

  <?php echo "This is inside mydiv"; ?>

 </div>

The resulting HTML will be a DIV that contains whatever you told PHP to output. This is usually enough.

Not sure whether this helps you. If it doesn't, maybe add some more detail about what you want to do.


For this use hidden varriables

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号