Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6105369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:58:01+00:00 2026-05-23T13:58:01+00:00

I have the following HTML code stored in a javascript string: and I am

  • 0

I have the following HTML code stored in a javascript string: and I am using Jquery 1.6.1 from google CDN

console.log(string):

<a><div class='product-autocomplete-result'>
            <div class='cell img'>
              <img src='http://beta.prizzm.com.s3.amazonaws.com/uploads/product_image/image/1/thumb_serrano_navy_1.jpg'>
            </div>
            <div class='cell'>
              <h2><a href="/products/1">Serrano Hobo</a></h2>
              <div class='clear'></div>
              <a href="#">0 people have this</a>
              <span>Rating 3</span>
              <div id='stars-wrapper-1'>
                <select>
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3" selected="selected">3</option>
                  <option value="4">4</option>
                  <option value="5">5</option>
                </select>
              </div>
            </div>
            <div class='cell'>
              <a href="#" class="button">I have this</a>
              <a href="#" class="button">I want this</a>
            </div>
          </div></a>

When I try to wrap this with JQuery, and output it, Jquery ends up closing my first <a> tag, and throwing other <a> tags in the code at seemingly random places, producing that in the screenshot here: (took screenshot because the output formatting was so bad)

enter image description here

The differences is that it
* closes the first <a> right away,
* inserts second <a> surrounding my first <div>
* inserts third <a> after my second <div> before the <h2>
* inserts a 4th <a> after the <h2> and before the intended <a>

As a result this is really messing up the autocomplete code that I use afterwards. This two snippets were literally generated one right after the other:

console.log(code);
console.log($(code));

Could someone please tell me whats going on an how to fix it?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:58:02+00:00Added an answer on May 23, 2026 at 1:58 pm

    Block elements are not allowed inside <a> elements. The browser tries to correct this but seems to produce invalid HTML code.

    Make sure you have only inline elements inside.

    Why do you have the outer <a> element anyway? It seems to serve no purpose. It does not even have an href attribute, which is invalid as well.

    Just remove it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my file to load a div with HTML
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
I have the following html.erb code that I'm looking to move to Haml: <span
I have the following code <html> <head> <title>Test</title> <style type=text/css> <!-- body,td,th { color:
I have a HTML file that has code similar to the following. <table> <tr>
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have the following issue. I have a google map (using YM4r + Geokit)
I have the following HTML code: <input type=checkbox value=1 /> <input type=checkbox value=2 />
I have the following html code: <ul class=smenu> <li class=smenuitem><a href=http://ux.stackexchange.com/></a></li> <li class=smenuitem><a href=http://area51.stackexchange.com/></a></li>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.