How would I go about disecting an id, turning this id="type=2owner=6page=1" into this:
var type = "2"; // or what ever is after type= but before owner=
var owner = "6"; // or what ever is after owner= but before page=
var page = "1"; // or what ever is after page=
The numbers won’t always be the same or single digit.
You can accomplish what you’re trying to do, but you should almost certainly be using data attributes instead.
Instead of packing data into your
idattribute, use separatedata-attributes:jQuery gives you a very easy syntax for accessing an element’s data attributes:
Or, for changing/adding new data attributes:
If you’re unable to add data attributes to your markup (if, for example, you’re only consuming the HTML and not generating it) you can use regular expressions to pull the
idattribute apart:Any of the above will return a two element array, where the second element is the digit in question.