SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: remove html tag

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    remove html tag

    How can I remove the following tag with jquery?


    <p align="center">Click here <a href="http://www.domain.com/" target="_blank">My domain</a></p>

    Tried

    jQuery('<p align="center">Click here <a href="http://www.domain.com/" target="_blank">My domain</a></p>').replaceWith('');

    but it does not work

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Just do something to target that p and remove it.

    With that small snippet I can't tell you exactly, but something like:
    jQuery('p').remove()

    would do the trick.

    The remove function removes anything in the list, so you just have to get that p in it's list and call remove. Just be careful of removing too much (for example, don't use that exact code because it'll remove every p).

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand. p tag does not have class

    Won't this code jQuery('p').remove() remove all p tags from html?

    thanks

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,840
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by pedroz View Post
    IWon't this code jQuery('p').remove() remove all p tags from html?
    Yes. You'll need something in one of the attributes of the tag that will identify the specific tag if you want to just remove that one.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Yeah, like I said, just 'p' will remove everything.

    With that little snippet of code I can't help you narrow it down any more.

    If you give us a larger chunk of code we probably can help you though.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •