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 8932001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:14:33+00:00 2026-06-15T09:14:33+00:00

In pure javascript (not using JQuery/dojo/etc), what is the best/easiest/quickest way to split a

  • 0

In pure javascript (not using JQuery/dojo/etc), what is the best/easiest/quickest way to split a string, such as

var tempString = '<span id="35287845" class="smallIcon" title="time clock" style="color:blue;font-size:14px;" contenteditable="false">cookie</span>';

into

var id = 'id="35287845"';
var class = 'class="smallIcon"';
var title = 'title="time clock"';
var style = 'style="color:blue;font-size:14px;"';
var contenteditable = 'contenteditable="false"';

Things to note:

  • a “space” cannot be used as a proper delimiter, since it may appear in a value, such as title, above (time clock).

  • maintaining the double quotes around each variable, such as id=”35287845″ is important

  • the opening/closing span tags can be discarded, as well as the content, which in this case, is “cookie”

  • 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-06-15T09:14:35+00:00Added an answer on June 15, 2026 at 9:14 am

    Here is one approach, which is to place the input string as innerhtml into a javascript created dom element and then leverage the attributes array

    //Input html string
    var tempString = '<span id="35287845" class="smallIcon" title="time clock" style="color:blue;font-size:14px;" contenteditable="false">cookie</span>';
    
    //make element to contain html string
    var tempDiv = document.createElement("div");
    
    //place html string as innerhtml to temp element
    tempDiv.innerHTML = tempString;
    
    //leverage attributes array on element
    var attributeArray = tempDiv.firstChild.attributes;
    
    //log results
    console.log(attributeArray);
    

    Note that you may now do something like

    var classString = attributeArray.class;
    

    or

    var titleString = attributeArray.title;
    

    Edit

    Here is a function that will do it:

    function getAttributesFromString(htmlString)
    {
     var tempDiv = document.createElement("div");
     tempDiv.innerHTML = htmlString;
     return tempDiv.firstChild.attributes;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using either pure Javascript or jQuery, how do I scroll the page so that
I make this post because a script of pure javascript tooltips, no jquery and
I was wondering if anyone happens to know of a jQuery (or pure javascript)
I've seen it's jquery equivalent: $('input[value=something]'); But how do you select it using pure
I'm using jQuery.load to load in some content but for SEO and for JavaScript-disabled
I am using Raphael JS, but I think this is pure JavaScript or maybe
I am using JavaScript Lint in vim. Recently I converted my pure JavaScript to
Question : Beginner Level Code: Pure Javascript I had created a web page in
I have a web application written in pure JavaScript (no pre-generated HTML except for
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object

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.