0
<p data-p-id="787f8218ddeb003c4e4115791dbd3d64">I WANT TO SELECT THIS TEXT</p>
<p data-p-id="fffa2fbdd488d59cd9006f69c502da0c">AND THIS TEXT</p>`
<p data-p-id="8283e3fcff081b550ad589abf1c97d96">AND THIS TEXT</p>
<p data-p-id="9a20d2be577597b30b603e168918384e">THIS TEXT ALSO</p>

I just want to select <p> tag with data-p-id on it. How can I do it in jQuery or strip_html in PHP?

Please help...sorry for poor english!

urbz
  • 2,663
  • 1
  • 19
  • 29

2 Answers2

0

PHP's strip_tag — Strip HTML and PHP tags from a string.

If you want to select all p tag and then get the data-p-id on each p tag, this is what you do:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">

// When page loads
$(function()
{
    $('p').each(function() {
        console.log('data-p-id = ' + $(this).attr('data-p-id'));
    });
});  

</script>


<p data-p-id="787f8218ddeb003c4e4115791dbd3d64">I WANT TO SELECT THIS TEXT</p>
<p data-p-id="fffa2fbdd488d59cd9006f69c502da0c">AND THIS TEXT</p>
<p data-p-id="8283e3fcff081b550ad589abf1c97d96">AND THIS TEXT</p>
<p data-p-id="9a20d2be577597b30b603e168918384e">THIS TEXT ALSO</p>

Check the console output and you will see this:

enter image description here

Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • thank you very much sir ....thanks for the quick reply....follow up question.. how about in php sir is there a way to select

    tag with p-data-id on it???

    – eman_invok05 Jun 19 '14 at 13:38
  • @eman_invok05 See: [DOMDocument Class](http://www.php.net//manual/en/class.domdocument.php#class.domdocument) – Rahil Wazir Jun 19 '14 at 13:41
  • You should avoid using `attr` instead use `prop`. [Reference](http://jquery.com/upgrade-guide/1.9/#attr-versus-prop-) – Rahil Wazir Jun 19 '14 at 13:44
  • @RahilWazir thank you sir...i will check this one :D thanks for your quick reply – eman_invok05 Jun 19 '14 at 13:49
0

In jquery: $("div[data-p-id]")

For example, to set the background golour of all these div tags to yellow, use:

$(document).ready(function(){
  $("div[data-p-id]").css("background-color","yellow");});
</script>

Remember to load the jquery library before calling the above function.

trees_are_great
  • 3,881
  • 3
  • 31
  • 62